Hungry_DinoBaby Posted February 9, 2021 Report Posted February 9, 2021 1 hour ago, Nimmakai said: It is a modified binary search problemĀ cc @friesNfrappe Are u able to solve this problem?Ā Ā edhi medium level, naku easy level ke vachipothundiĀ š¤ Ā 1 Quote
Nimmakai Posted February 9, 2021 Report Posted February 9, 2021 4 minutes ago, Hungry_DinoBaby said: Are u able to solve this problem?Ā Ā Vere similar problem chesa, like oka number istadu, a number ni e twisted array lo ekada undo index return cheyali.. so twisted array ante binary search gurthochindhi. Arrays lo medium idi 1 Quote
Hungry_DinoBaby Posted February 9, 2021 Report Posted February 9, 2021 Just now, Nimmakai said: Vere similar problem chesa, like oka number istadu, a number ni e twisted array lo ekada undo index return cheyali.. so twisted array ante binary search gurthochindhi. Arrays lo medium idi Cool. Atleast you have an idea.Ā Quote
mmharshaa Posted February 9, 2021 Report Posted February 9, 2021 14 minutes ago, dasari4kntr said: Ā Ā Ā Ā Ā Ā Ā Ā i will lift this thread tommrrow... my logic is failing with [-1,-1,-1,-1] input...once i solve that..i will lift it again... Ā BTW..if any one want to practice...sample inputs as below..to test your code..for edge cases... [1] [3,1] [1,1] [2,2,2,0,1] my logic should work for your inputs. Only cases i didn't cover were one and zero elements Quote
Vaampire Posted February 9, 2021 Report Posted February 9, 2021 public class Solution { Ā Ā public int FindMin(int[] nums) { Ā Ā Ā Ā int left = 0; Ā Ā Ā Ā int right = nums.Length - 1; Ā Ā Ā Ā while(left < right){ Ā Ā Ā Ā Ā Ā int mid = (left + right) / 2; Ā Ā Ā Ā Ā Ā if(nums[mid] < nums[right]) right = mid; Ā Ā Ā Ā Ā Ā else if(nums[mid] > nums[right]) left = mid + 1; Ā Ā Ā Ā Ā Ā else right--; Ā Ā Ā Ā } Ā Ā Ā Ā return nums[left]; Ā Ā } } 2 Quote
Vaampire Posted February 9, 2021 Report Posted February 9, 2021 Just now, Vaampire said: public class Solution { Ā Ā public int FindMin(int[] nums) { Ā Ā Ā Ā int left = 0; Ā Ā Ā Ā int right = nums.Length - 1; Ā Ā Ā Ā while(left < right){ Ā Ā Ā Ā Ā Ā int mid = (left + right) / 2; Ā Ā Ā Ā Ā Ā if(nums[mid] < nums[right]) right = mid; Ā Ā Ā Ā Ā Ā else if(nums[mid] > nums[right]) left = mid + 1; Ā Ā Ā Ā Ā Ā else right--; Ā Ā Ā Ā } Ā Ā Ā Ā return nums[left]; Ā Ā } } Copied from my leetcode solutions. Eppudo 4 yrs back chesa 1 Quote
Hungry_DinoBaby Posted February 9, 2021 Report Posted February 9, 2021 8 hours ago, johnydanylee said: @Arey_enti_ra_idi Vuuuu Quote
dasari4kntr Posted February 9, 2021 Author Report Posted February 9, 2021 my logic....kind of overkilled...but working... Ā /** * @param {number[]} nums * @return {number} */ var findMin = function(nums) { if(nums && nums.length===1) { return nums[0]; } if(nums && nums.length>1) { const middle = nums.length/2; const left = nums.slice(0, middle); const right = nums.slice(middle); return findMin(left) > findMin(right) ? findMin(right) : findMin(left); } }; Ā Quote
Vaampire Posted February 9, 2021 Report Posted February 9, 2021 18 minutes ago, dasari4kntr said: my logic....kind of overkilled...but working... Ā /** * @param {number[]} nums * @return {number} */ var findMin = function(nums) { if(nums && nums.length===1) { return nums[0]; } if(nums && nums.length>1) { const middle = nums.length/2; const left = nums.slice(0, middle); const right = nums.slice(middle); return findMin(left) > findMin(right) ? findMin(right) : findMin(left); } }; Ā This works but complexity is O(n).Ā if i understood ur solution correctly, u r totally ignoring the fact that its rotated sorted array. Ā Ur solution will work even for unsorted array. recursive alg should be used very cautiously. also ur solution used extra space too by coping elements into variables.. Ā sorry, dint mean to discourage you. I am just giving feed back as an interviewer 1 Quote
Nimmakai Posted February 9, 2021 Report Posted February 9, 2021 1 minute ago, Vaampire said: This works but complexity is O(n).Ā if i understood ur solution correctly, u r totally ignoring the fact that its rotated sorted array. Ā Ur solution will work even for unsorted array. recursive alg should be used very cautiously. also ur solution used extra space too by coping elements into variables.. Ā sorry, dint mean to discourage you. I am just giving feed back as an interviewer @VaampireĀ bro 3 yearsĀ experience petkoni jobs apply chestheĀ , leetcode lo nunchi medium a adgutara or hard kuda na ? Quote
Marsmangalodu Posted February 9, 2021 Report Posted February 9, 2021 Binary search variation O(log n) tho cheyyali ani intervier expectation Quote
Vaampire Posted February 9, 2021 Report Posted February 9, 2021 29 minutes ago, Nimmakai said: @VaampireĀ bro 3 yearsĀ experience petkoni jobs apply chestheĀ , leetcode lo nunchi medium a adgutara or hard kuda na ? Leetcode hard medium or easy totally depends on interviewer.Ā manchollu avuthey hard eppudu adagaru general gaa. Also lc rating doesnt make sense. Konni easy probs ki hard tag pettadu. Vice versa too 1 Quote
dasari4kntr Posted February 9, 2021 Author Report Posted February 9, 2021 1 hour ago, Vaampire said: This works but complexity is O(n).Ā if i understood ur solution correctly, u r totally ignoring the fact that its rotated sorted array. Ā Ur solution will work even for unsorted array. recursive alg should be used very cautiously. also ur solution used extra space too by coping elements into variables.. Ā sorry, dint mean to discourage you. I am just giving feed back as an interviewer ok..got it... Quote
Chay Posted February 9, 2021 Report Posted February 9, 2021 16 hours ago, Hungry_DinoBaby said: Are u able to solve this problem?Ā Ā edhi medium level, naku easy level ke vachipothundiĀ š¤ Ā ayyo watch poyindaĀ 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.