From 40430b38162ee3b7269bd6ebf52a683655ac0627 Mon Sep 17 00:00:00 2001 From: aadil42 <77232799+aadil42@users.noreply.github.com> Date: Thu, 20 Feb 2025 11:25:07 +0530 Subject: [PATCH] Create 1980-find-unique-binary-string.js Solved find-unique-binary-string --- javascript/1980-find-unique-binary-string.js | 35 ++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 javascript/1980-find-unique-binary-string.js diff --git a/javascript/1980-find-unique-binary-string.js b/javascript/1980-find-unique-binary-string.js new file mode 100644 index 000000000..6e0443c83 --- /dev/null +++ b/javascript/1980-find-unique-binary-string.js @@ -0,0 +1,35 @@ +/** + * BackTracking | Recursion | BruteForce + * Time O(2^n) | Space O(n) + * https://leetcode.com/problems/find-unique-binary-string + * @param {string[]} nums + * @return {string} + */ +var findDifferentBinaryString = function(nums) { + + let isFound = false; + let missing = ""; + const present = new Set(nums); + const n = nums[0].length; + + const dfs = (binaryStr) => { + + if (isFound) return; + + if (binaryStr.length === n) { + if (!present.has(binaryStr)) { + isFound = true; + missing = binaryStr; + return; + } + + return; + } + + dfs(binaryStr+"0"); + dfs(binaryStr+"1"); + } + + dfs(""); + return missing; +};