Udyan is here
Udyan is here
  • 31
  • 10 528
779. K-th Symbol in Grammar | O(N) | Java | Hindi
In this video, we'll tackle question number 779. K th Symbol in Grammar on Leetcode using Java. The explanation will be provided in Hindi for easy understanding.
You can find the problem link in the First Comment.
If you have any questions or need further assistance, please don't hesitate to reach out to me through my Linktree profile: linktr.ee/udyanojha
zhlédnutí: 217

Video

515. Find Largest Value in Each Tree Row
zhlédnutí 49Před 10 měsíci
In this video, we'll tackle question number 515. Find Largest Value in Each Tree Row on Leetcode using Java. The explanation will be provided in Hindi for easy understanding. If you have any questions or need further assistance, please don't hesitate to reach out to me through my Linktree profile: linktr.ee/udyanojha
341. Flatten Nested List Iterator | Medium | Recursion | Java | Hindi
zhlédnutí 59Před 10 měsíci
In this video, we'll tackle question number 341. Flatten Nested List Iterator on Leetcode using Java. The explanation will be provided in Hindi for easy understanding. You can find the problem link here: leetcode.com/problems/flatten-nested-list-iterator/ If you have any questions or need further assistance, please don't hesitate to reach out to me through my Linktree profile: linktr.ee/udyanojha
1361. Validate Binary Tree Nodes | Medium | Memoization | Java | Hindi
zhlédnutí 102Před 10 měsíci
In this video, we'll tackle question number 1361. Validate Binary Tree Nodes on Leetcode using Java. The explanation will be provided in Hindi for easy understanding. You can find the problem link here: leetcode.com/problems/validate-binary-tree-nodes/ If you have any questions or need further assistance, please don't hesitate to reach out to me through my Linktree profile: linktr.ee/udyanojha
119. Pascal's Triangle II | O(N) | Java | Hindi
zhlédnutí 72Před 10 měsíci
In this video, we'll tackle question number 119. Pascal's Triangle II on Leetcode using Java. First, we will do O(n^2) and then optimise O(n). The explanation will be provided in Hindi for easy understanding. You can find the problem link in the First Comment. If you have any questions or need further assistance, please don't hesitate to reach out to me through my Linktree profile: linktr.ee/ud...
1269. Number of Ways to Stay in the Same Place After Some Steps | Hard | Memoization | Java | Hindi
zhlédnutí 32Před 10 měsíci
In this video, we'll tackle question number 1269. Number of Ways to Stay in the Same Place After Some Steps on Leetcode using Java. The explanation will be provided in Hindi for easy understanding. You can find the problem link here: leetcode.com/problems/number-of-ways-to-stay-in-the-same-place-after-some-steps/ If you have any questions or need further assistance, please don't hesitate to rea...
746. Min Cost Climbing Stairs | EASY | Hindi | Java | DP RECURSION
zhlédnutí 85Před 10 měsíci
In this video, we'll tackle question number 746. Min Cost Climbing Stairs on Leetcode using Java. We'll demonstrate a solution with a time complexity of O(n). The explanation will be provided in Hindi for easy understanding. You can find the problem link here: leetcode.com/problems/min-cost-climbing-stairs/ If you have any questions or need further assistance, please don't hesitate to reach out...
1095. Find in Mountain Array | HARD | Hindi | Java Binary Search
zhlédnutí 144Před 10 měsíci
In this video, we'll tackle question number 1095. Find in Mountain Array on Leetcode using Java. We'll demonstrate a solution with a time complexity of O(log n). The explanation will be provided in Hindi for easy understanding. You can find the problem link here: leetcode.com/problems/find-in-mountain-array/ If you have any questions or need further assistance, please don't hesitate to reach ou...
2251. Number of Flowers in Full Bloom | HARD | Hindi | Java Binary Search
zhlédnutí 27Před 10 měsíci
In this video, we'll tackle question number 2251. Number of Flowers in Full Bloom on Leetcode using Java. We'll demonstrate a solution with a time complexity of O(n log n). The explanation will be provided in Hindi for easy understanding. You can find the problem link here: leetcode.com/problems/number-of-flowers-in-full-bloom/ If you have any questions or need further assistance, please don't ...
34 Find First and Last Position of Element in Sorted Array | MEDIUM | Binary Search
zhlédnutí 47Před 10 měsíci
In this video, we'll tackle question number 34. Find First and Last Position of Element in Sorted Array on Leetcode using Java. We'll demonstrate an efficient solution with a time complexity of O(log n) and a space complexity of O(1). The explanation will be provided in Hindi for easy understanding. You can find the problem link here: leetcode.com/problems/find-first-and-last-position-of-elemen...
1962. Remove Stones to Minimize the Total | Java Hindi | Priority Queue | LeetCode daily
zhlédnutí 94Před rokem
Hey folks! In this video, we discussed 1962 Remove Stones to Minimize the Total using Priority Queue Hindi using Java Language. 1962. Remove Stones to Minimize the Total Problem link: leetcode.com/problems/remove-stones-to-minimize-the-total/ If you have any queries reach out to me at linktr.ee/udyanojha
2389 Longest Subsequence With Limited Sum | LeetCode JAVA HINDI | TreeMap Prefix Sum |
zhlédnutí 159Před rokem
Hey folks! In this video, we discussed Longest Subsequence With Limited Sum using Prefix Sum and Tree Map in Hindi using Java Language. 2389. Longest Subsequence With Limited Sum Problem link: leetcode.com/problems/longest-subsequence-with-limited-sum/ If you have any queries reach out to me at linktr.ee/udyanojha
Leetcode || 739. Daily Temperatures || Hindi Java || O(N) MONOTONIC STACK 📚
zhlédnutí 382Před rokem
Hi folks! Here we are solving Daily Temperature with the help of a monotonic stack data structure in java language. If you have any doubts do reach out. 🐥Twitter: UdyanOjha 💻 Linkedin: www.linkedin.com/in/udyanojha/ 🤳 Instagram: udyanojha Problem link: leetcode.com/problems/daily-temperatures/ If you have any queries reach out to me at linktr.ee/udyanojha
150 Evaluate Reverse Polish Notation | JAVA Leetcode Daily December | Hindi
zhlédnutí 601Před rokem
Hi folks! Here we are solving Evaluate Reverse Polish Notation with the help of stack data structure in java language. If you have any doubt do reach out. Problem link : leetcode.com/problems/decode-ways/ If you have any query reach out to me at linktr.ee/udyanojha
872 Leaf Similar Trees using STACK
zhlédnutí 101Před rokem
Hi folks! Here we are solving Leaf Similar Trees in Java. Easy explanation in Hindi. Problem link: leetcode.com/problems/leaf-similar-trees/ If you have any queries reach out to me at linktr.ee/udyanojha
446. Arithmetic Slices II - Subsequence | HARD | Leetcode daily | JAVA | Hindi
zhlédnutí 270Před rokem
446. Arithmetic Slices II - Subsequence | HARD | Leetcode daily | JAVA | Hindi
1235. Maximum Profit in Job Scheduling | HARD | JAVA | Hindi
zhlédnutí 579Před rokem
1235. Maximum Profit in Job Scheduling | HARD | JAVA | Hindi
766. Toeplitz Matrix | Leetcode Hindi | Java
zhlédnutí 1,6KPřed rokem
766. Toeplitz Matrix | Leetcode Hindi | Java
Increasing Triplet Subsequence || Leetcode JAVA || O(N)
zhlédnutí 1KPřed rokem
Increasing Triplet Subsequence || Leetcode JAVA || O(N)
JAVA | 981. Time Based Key-Value Store | HINDI | LeetCode Daily
zhlédnutí 917Před rokem
JAVA | 981. Time Based Key-Value Store | HINDI | LeetCode Daily
112 Path Sum | JAVA | HINDI
zhlédnutí 69Před rokem
112 Path Sum | JAVA | HINDI
1578 Minimum Time to Make Rope Colorful |💯Runtime Tip | JAVA | HINDI
zhlédnutí 276Před rokem
1578 Minimum Time to Make Rope Colorful |💯Runtime Tip | JAVA | HINDI
1155 Number of Dice Rolls With Target Sum | Recursion | Memoization | Tabulation DP | JAVA | HINDI
zhlédnutí 239Před rokem
1155 Number of Dice Rolls With Target Sum | Recursion | Memoization | Tabulation DP | JAVA | HINDI
JAVA | 91 Decode Ways | HINDI | LeetCode Daily
zhlédnutí 177Před rokem
JAVA | 91 Decode Ways | HINDI | LeetCode Daily
622 Design Circular Queue | Leetcode | Java | Hindi Using Array
zhlédnutí 867Před rokem
622 Design Circular Queue | Leetcode | Java | Hindi Using Array
1680 Concatenation of Consecutive Binary Numbers O(N) JAVA | HINDI | BIT MANIPULATION
zhlédnutí 239Před rokem
1680 Concatenation of Consecutive Binary Numbers O(N) JAVA | HINDI | BIT MANIPULATION
JAVA | 985 Sum of Even Numbers After Queries | HINDI | LeetCode Daily
zhlédnutí 443Před rokem
JAVA | 985 Sum of Even Numbers After Queries | HINDI | LeetCode Daily
609 Find Duplicate File in System | Hindi | Leetcode | Easy Explain
zhlédnutí 158Před rokem
609 Find Duplicate File in System | Hindi | Leetcode | Easy Explain
Hindi 1770 Maximum Score from Performing Multiplication Operations Leetcode HIndi
zhlédnutí 199Před rokem
Hindi 1770 Maximum Score from Performing Multiplication Operations Leetcode HIndi
948 Bag of Tokens Leetcode Hindi
zhlédnutí 948Před rokem
948 Bag of Tokens Leetcode Hindi

Komentáře

  • @Yugalnasare
    @Yugalnasare Před 2 měsíci

    Thik Hai.....

  • @testtest-oq9qk
    @testtest-oq9qk Před 2 měsíci

    why we need to define next() and hasNext() as we are not using it here?? Is it required ??

    • @udyanishere
      @udyanishere Před 2 měsíci

      The aim of this question is to design an Iterator, and it is defined in question to have next() and hasNext() implemented.

  • @rangan_dasgupta
    @rangan_dasgupta Před 4 měsíci

    Dammmmmmmmmmm❤❤❤❤❤

  • @rinkygarg7350
    @rinkygarg7350 Před 5 měsíci

    Appreciate the way of explaining 👏 👌

  • @ansmustafa2245
    @ansmustafa2245 Před 6 měsíci

    Very very well explanation

  • @manishamaurya485
    @manishamaurya485 Před 6 měsíci

    code in c++ class Solution { public: int bagOfTokensScore(vector<int>& tokens, int power) { sort(tokens.begin(),tokens.end()); int s=0,e=tokens.size()-1; int maxi=0; int curr=0; while(s<=e){ if(power>=tokens[s]){ curr+=1; … } maxi=max(maxi,curr); } return maxi; } };

  • @climacry
    @climacry Před 6 měsíci

    btw i liked your video and its truely better then others explanation it was just like my big brother explaining me things

    • @udyanishere
      @udyanishere Před 3 měsíci

      This means a lot to me. Connect on LinkedIn I’m glad to help.

  • @climacry
    @climacry Před 6 měsíci

    sir tell me one thing the second condition was when the score is atleast greater then 1 then why are you taking max >0?

  • @sonuprajapati3004
    @sonuprajapati3004 Před 6 měsíci

    Believe me you are explainig very good keep it up..

  • @amanraheja2905
    @amanraheja2905 Před 7 měsíci

    Bhai, mai ekdum yahi so raha tha par aapne kitni asaani se bta diya. Well done 👍

    • @udyanishere
      @udyanishere Před 7 měsíci

      Awesome h ye toh Aman bhai… lessgo 🔥

  • @Arya20012
    @Arya20012 Před 8 měsíci

    great explanation brother

  • @user-bb1di5fn9w
    @user-bb1di5fn9w Před 8 měsíci

    your explanation is really good . keep it up. please upload more videos if you can!

  • @manasgotefode
    @manasgotefode Před 8 měsíci

    Try this test case : 2,1,5,0,6,7 The compiler accept this test case but if we dry run this test case by our own the rule of i<j<k is not satisfied here

  • @franklind8569
    @franklind8569 Před 9 měsíci

    "Promo sm" 😭

  • @CodingJoySoul
    @CodingJoySoul Před 9 měsíci

    Bhai why did you stop making these videos?

    • @udyanishere
      @udyanishere Před 3 měsíci

      Bhai banaunga phirse. I miss these videos.

  • @VikalClasses
    @VikalClasses Před 9 měsíci

    You explained this the best way on entire CZcams ❤Now I m really looking forward to get solutions of entire leetcode from you 😆

    • @udyanishere
      @udyanishere Před 9 měsíci

      I'm happy to help! Zaroor. Will solve many more questions together. New vid coming soon.

  • @udyanishere
    @udyanishere Před 10 měsíci

    Let's Connect: linktr.ee/udyanojha

  • @udyanishere
    @udyanishere Před 10 měsíci

    leetcode.com/problems/k-th-symbol-in-grammar/

  • @udyanishere
    @udyanishere Před 10 měsíci

    Can you tell Space Complexity here?

  • @udyanishere
    @udyanishere Před 10 měsíci

    class Solution { public boolean validateBinaryTreeNodes(int n, int[] leftChild, int[] rightChild) { HashMap<Integer, ArrayList<Integer>> parentChild = new HashMap<>(); HashMap<Integer, Integer> childParent = new HashMap<>(); for(int node = 0; node< n; node++) { int left = leftChild[node]; if(left != -1) { parentChild.putIfAbsent(node, new ArrayList<>()); parentChild.get(node).add(left); if(childParent.containsKey(left)){ return false; } else { childParent.put(left, node); } } int right = rightChild[node]; if(right != -1) { parentChild.putIfAbsent(node, new ArrayList<>()); parentChild.get(node).add(right); if(childParent.containsKey(right)){ return false; } else { childParent.put(right, node); } } } // Root? Multiple Hai ya nhi h // int root = -1; Integer root = null; for(int node = 0; node< n; node++) { if(!childParent.containsKey(node)) { if(root == null) { root = node; } else { return false; } } } if(root == null) { return false; } HashSet<Integer> visited = new HashSet<>(); Queue<Integer> que = new LinkedList<>(); que.add(root); while(!que.isEmpty()) { int node = que.remove(); visited.add(node); if(parentChild.containsKey(node)) { for(int child : parentChild.get(node)) { que.add(child); } } } return visited.size() == n; } }

  • @CodingJoySoul
    @CodingJoySoul Před 10 měsíci

    Awesome explanation

  • @udyanishere
    @udyanishere Před 10 měsíci

    class Solution { Integer[][] dp = new Integer[501][501]; public int numWays(int steps, int arrLen) { return helper(0, steps, arrLen); } private int helper(int i, int k, int len) { if(dp[i][k] != null) return dp[i][k]; if(i == 0 && k == 0) return 1; if(k==0) return 0; int left = (i > 0) ? helper(i-1, k-1, len) : 0; int stay = helper(i, k-1, len); int right = (i<len-1) ? helper(i+1, k-1, len) : 0; int total = ((left + stay) % (int)(1e9+7) + right) % (int)(1e9+7); return dp[i][k] = total; } }

  • @udyanishere
    @udyanishere Před 10 měsíci

    Thanks for being here Coding JoySoul!

  • @CodingJoySoul
    @CodingJoySoul Před 10 měsíci

    Bhaiya, aap ab lectures nhin banaoge kya?

    • @udyanishere
      @udyanishere Před 10 měsíci

      Bana rha hu. Kal Delhi me nhi tha.

  • @CodingJoySoul
    @CodingJoySoul Před 10 měsíci

    Bhaiya aapne video hi nhin daali Aaj, Main apne friends ko aapka channel recommend karta hun

    • @udyanishere
      @udyanishere Před 10 měsíci

      Sorry kal emergency me jaana pada kahin! WIll upload aajse. Your supports matters a lot. Thanks

  • @CodingJoySoul
    @CodingJoySoul Před 10 měsíci

    Bhaiya, Congratulations for 700 subscribers

  • @CodingJoySoul
    @CodingJoySoul Před 10 měsíci

    I felt that in this video, explanation was not beginner friendly

    • @udyanishere
      @udyanishere Před 10 měsíci

      Yes I understand. Will record and post again.

    • @udyanishere
      @udyanishere Před 10 měsíci

      Thanks for letting me know.

  • @udyanishere
    @udyanishere Před 10 měsíci

    Tabulation: class Solution { public int minCostClimbingStairs(int[] cost) { int[] dp = new int[cost.length]; int n = cost.length-1; dp[0] = cost[0]; dp[1] = cost[1]; for(int i = 2; i < cost.length; i++) { dp[i] = cost[i] + Math.min(dp[i-1], dp[i-2]); } return Math.min(dp[n-1], dp[n]); } }

  • @udyanishere
    @udyanishere Před 10 měsíci

    JAVA Memoization: class Solution { public int minCostClimbingStairs(int[] cost) { int[] dp = new int[cost.length]; Arrays.fill(dp, -1); return Math.min(helper(cost, 0, dp), helper(cost, 1, dp)); } private int helper(int[] cost, int idx, int[] dp) { if(idx>= cost.length) return 0; if(dp[idx]!= -1) return dp[idx]; return dp[idx] = cost[idx] + Math.min(helper(cost, idx+1, dp), helper(cost, idx+2, dp)); } }

  • @CodingJoySoul
    @CodingJoySoul Před 11 měsíci

    Just a request. Please make all the Leetcode Solution videos of graph topic. Itna awesome padha rahe ho aap

    • @udyanishere
      @udyanishere Před 10 měsíci

      Sure. I'll revise and revisit Graph again. Thoda time lagega. I'll start.

  • @CodingJoySoul
    @CodingJoySoul Před 11 měsíci

    Glad to know that you are back.... frequent viewer of your channel. One thing is for sure... Your explanation is good.

    • @udyanishere
      @udyanishere Před 10 měsíci

      Means a lot. Will share my updates too. Would love to connect. ✨

  • @udyanishere
    @udyanishere Před 11 měsíci

    class Solution { public int findInMountainArray(int target, MountainArray mountainArr) { // Find Peak of Mountain int peakIdx = findPeak(mountainArr); // Now BS in left_ASC and right_DSC range int res = -1; // // EDGE CASE if(target > mountainArr.get(peakIdx)) return -1; res = BS_ASC(target, mountainArr, 0, peakIdx); if(res != -1) return res; return BS_DSC(target, mountainArr, peakIdx, mountainArr.length()-1); } private int BS_ASC(int target, MountainArray arr, int st, int ed) { while(ed>=st) { int mid = st + (ed-st)/2; if(arr.get(mid) == target) { return mid; } else if(arr.get(mid) > target) { ed = mid - 1; } else { st = mid + 1; } } return -1; } private int BS_DSC(int target, MountainArray arr, int st, int ed) { while(ed>=st) { int mid = st + (ed-st)/2; if(arr.get(mid) == target) { return mid; } else if(arr.get(mid) > target) { st = mid + 1; } else { ed = mid - 1; } } return -1; } private int findPeak(MountainArray arr) { int st = 0; int ed = arr.length() - 1; while(ed>=st) { int mid = st + (ed-st)/2; if(mid == 0) return 1; if(arr.get(mid-1) < arr.get(mid) && arr.get(mid) > arr.get(mid+1)) { return mid; } else if(arr.get(mid-1) < arr.get(mid) && arr.get(mid) < arr.get(mid+1)) { st = mid+1; } else { ed = mid-1; } } return -1; } }

  • @udyanishere
    @udyanishere Před 11 měsíci

    class Solution { public int[] fullBloomFlowers(int[][] flowers, int[] people) { // Clone arr // Sort Flowers in St ASC // Sort Flowers in Ed ASC // O(n + nlogn + nlogn) // Do Search in st Just <= peoplei AS stIdx // Do Search in ed Just > peoplei // O(n + nlogn + nlogn + logn + logn) // In Res arr push 1 + stIdx - edIdx // it means number of flowers that bloom before = to people time - number of flowers that deBloom before people time int[] res = new int[people.length]; int[][] stFlowers = flowers.clone(); Arrays.sort(stFlowers, (a, b) -> a[0]>b[0] ? 1 : -1); int[][] edFlowers = flowers.clone(); Arrays.sort(edFlowers, (a, b) -> a[1]>b[1] ? 1 : -1); // for(int[] arr : stFlowers) System.out.println(arr[0] +" "+ arr[1]); // for(int[] arr : edFlowers) System.out.println(arr[0] +" "+ arr[1]); for(int i = 0; i<people.length; i++) { res[i] = 1 + stBS(stFlowers, people[i]) - edBS(edFlowers, people[i]); } // O(n + nlogn + nlogn + logn + logn + n) return res; } private int stBS(int[][] flowers, int x) { int stIdx =-1; int st = 0; int ed = flowers.length - 1; while(ed>=st) { int mid = st + (ed-st)/2; if(flowers[mid][0] <= x) { stIdx = mid; st = mid+1; } else { ed = mid-1; } } return stIdx; } private int edBS(int[][] flowers, int x) { int edIdx = -1; int st = 0; int ed = flowers.length - 1; while(ed>=st) { int mid = st + (ed-st)/2; if(flowers[mid][1] < x) { edIdx = mid; st = mid+1; } else { ed = mid-1; } } return edIdx+1; } }

  • @OmrajSharma
    @OmrajSharma Před 11 měsíci

    Good work bhai 👍

  • @udyanishere
    @udyanishere Před 11 měsíci

    Java Soln: class Solution { public int[] searchRange(int[] nums, int target) { int leftIdx = findLeft(nums, target); int rightIdx = findRight(nums, target); return new int[] {leftIdx, rightIdx}; } private int findLeft(int[] nums, int target) { int res = -1; int st = 0; int ed = nums.length-1; while(ed>=st) { int mid = st + (ed-st)/2; if(nums[mid]==target) { res = mid; ed = mid-1; } else if(nums[mid] > target) { ed = mid-1; } else { st = mid+1; } } return res; } private int findRight(int[] nums, int target) { int res = -1; int st = 0; int ed = nums.length-1; while(ed>=st) { int mid = st + (ed-st)/2; if(nums[mid]==target) { res = mid; st = mid+1; } else if(nums[mid] > target) { ed = mid-1; } else { st = mid+1; } } return res; } }

  • @CodingJoySoul
    @CodingJoySoul Před 11 měsíci

    Please continue making the Leetcode solution videos again

  • @CodingJoySoul
    @CodingJoySoul Před 11 měsíci

    Why have you stopped making Leetcode solution videos. Please start making videos again, you are doing a good work. Please, please ,please

    • @udyanishere
      @udyanishere Před 10 měsíci

      Working on Graph, but first have to revise other required topics.

    • @CodingJoySoul
      @CodingJoySoul Před 10 měsíci

      @@udyanishere thanks Bhaiya 💯

  • @novicecoder5753
    @novicecoder5753 Před 11 měsíci

    Your approach is good but initially got below approach in my mind and implemented but after watching your solution it good class Solution { public static boolean checkToeplitz(int i, int j,int[][] matrix){ while(i < matrix.length && j < matrix[0].length){ if(matrix[i][j] != matrix[i-1][j-1]){ return false; } i++; j++; } return true; } public boolean isToeplitzMatrix(int[][] matrix) { int n = matrix.length; int m = matrix[0].length; //My approach is first check the first row whether it is diagonally perfect then check first column whether it is diagonally perfect. //row checking int currentRow = 0; for(int i=0;i<matrix[0].length;i++){ boolean res = checkToeplitz(currentRow+1,i+1,matrix); if(!res){ return false; } } //column checking //for this iteration i am considering as row int currentCol = 0; for(int j=1;j<matrix.length;j++){ boolean res = checkToeplitz(j+1,currentCol+1,matrix); if(!res){ return false; } } return true; } }

  • @PrashantKumar-fk8le

    Great Explanation

  • @poorpanda9033
    @poorpanda9033 Před rokem

    Very nice explanation ! Thank you so muchhhhh <3

  • @vinamrasangal8436
    @vinamrasangal8436 Před rokem

    bhadiya video thi, hai, nhi rahegi

  • @IraquiRizwanVlogs
    @IraquiRizwanVlogs Před rokem

    Bhai mujhe alog basic se learn krni hai.

  • @IraquiRizwanVlogs
    @IraquiRizwanVlogs Před rokem

    Excellent bro

  • @cooltomcatty
    @cooltomcatty Před rokem

    Wow what an explanation bro! 🤩🤩🤩 God bless you 🥰🥰🥰

  • @cooltomcatty
    @cooltomcatty Před rokem

    I just found that It's similar to partion sort (card game)

  • @videokingdom6076
    @videokingdom6076 Před rokem

    this code is not working bro 😢😢

  • @jitendrasoni_3510
    @jitendrasoni_3510 Před rokem

    Thanks buddy for making such a nice solution video.

  • @udyanishere
    @udyanishere Před rokem

    class Solution { public int[] answerQueries(int[] nums, int[] queries) { int[] prefixSum = new int[nums.length]; Arrays.sort(nums); TreeMap<Integer, Integer> map = new TreeMap<>(); prefixSum[0] = nums[0]; map.put(prefixSum[0], 1); for(int i = 1; i<nums.length; i++) { prefixSum[i] = prefixSum[i-1] + nums[i]; map.put(prefixSum[i], i+1); } int[] ans = new int[queries.length]; int k = 0; for(int query : queries) { Map.Entry<Integer, Integer> entry = map.floorEntry(query); if(entry != null) { ans[k] = entry.getValue(); } k++; } return ans; } }

  • @sonujangid7893
    @sonujangid7893 Před rokem

    Great explanation bro👌🏻