{"id":22513949,"url":"https://github.com/emahtab/convert-sorted-array-to-binary-search-tree","last_synced_at":"2026-01-28T15:32:43.282Z","repository":{"id":79525377,"uuid":"238745918","full_name":"eMahtab/convert-sorted-array-to-binary-search-tree","owner":"eMahtab","description":"Convert Sorted Array to Height Balanced Binary Search Tree","archived":false,"fork":false,"pushed_at":"2020-02-06T17:35:32.000Z","size":1,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-04T05:08:51.133Z","etag":null,"topics":["binary-search-tree","leetcode","problem-solving"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eMahtab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-06T17:32:38.000Z","updated_at":"2020-02-06T17:35:35.000Z","dependencies_parsed_at":"2023-05-23T13:46:42.814Z","dependency_job_id":null,"html_url":"https://github.com/eMahtab/convert-sorted-array-to-binary-search-tree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eMahtab/convert-sorted-array-to-binary-search-tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fconvert-sorted-array-to-binary-search-tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fconvert-sorted-array-to-binary-search-tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fconvert-sorted-array-to-binary-search-tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fconvert-sorted-array-to-binary-search-tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eMahtab","download_url":"https://codeload.github.com/eMahtab/convert-sorted-array-to-binary-search-tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eMahtab%2Fconvert-sorted-array-to-binary-search-tree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28846342,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-28T15:15:36.453Z","status":"ssl_error","status_checked_at":"2026-01-28T15:15:13.020Z","response_time":57,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["binary-search-tree","leetcode","problem-solving"],"created_at":"2024-12-07T03:15:14.002Z","updated_at":"2026-01-28T15:32:43.266Z","avatar_url":"https://github.com/eMahtab.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Convert Sorted Array to Binary Search Tree\n### https://leetcode.com/problems/convert-sorted-array-to-binary-search-tree\n\nGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.\n\nFor this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.\n```\nExample:\n\nGiven the sorted array: [-10,-3,0,5,9],\n\nOne possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST:\n\n      0\n     / \\\n   -3   9\n   /   /\n -10  5\n ```\n \n ## Implementation :\n \n ```java\n /**\n * Definition for a binary tree node.\n * public class TreeNode {\n *     int val;\n *     TreeNode left;\n *     TreeNode right;\n *     TreeNode(int x) { val = x; }\n * }\n */\nclass Solution {\n    public TreeNode sortedArrayToBST(int[] nums) {\n        if(nums == null || nums.length == 0)\n            return null;\n        return constructTree(nums, 0, nums.length - 1);\n    }\n    \n    public TreeNode constructTree(int[] nums, int left, int right){\n        if(left \u003e right)\n            return null;\n        int mid = left + (right - left) / 2;\n        TreeNode node = new TreeNode(nums[mid]);\n        node.left = constructTree(nums, left, mid -1);\n        node.right = constructTree(nums, mid+1, right);\n        return node;\n    }\n}\n \n ```\n \n ## References :\n 1. https://www.youtube.com/watch?v=PZYTs9y4f4o\n 2. https://www.youtube.com/watch?v=12omz-VAyRk\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fconvert-sorted-array-to-binary-search-tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femahtab%2Fconvert-sorted-array-to-binary-search-tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femahtab%2Fconvert-sorted-array-to-binary-search-tree/lists"}