Fogy Free
Fogy Free
  • 466
  • 24 107
1636 Sort Array by Increasing Frequency
1636 Sort Array by Increasing Frequency. - This Java code does these three things, It sorts the array based on increasing frequency of the values.
For values with the same frequency, it sorts them in decreasing order.
It handles both positive and negative numbers within the given constraints.
here is how it works:
1. We use a HashMap (frequencyMap) to count the frequency of each number in the input array.
2. We create a list of unique numbers from the keys of the frequency map.
3. We sort this list of unique numbers based on two criteria:
Primary: Increasing order of frequency
Secondary: For numbers with the same frequency, we sort in decreasing order of the numbers themselves
4. Finally, we create the result array by adding each number from our sorted list of unique numbers, repeating each number according to its frequency.
The time complexity is O(n log n) due to the sorting step, where n is the number of unique elements in the input array. The space complexity is O(n) for storing the frequency map and the list of unique numbers. thanks for watching and please subscribe.
Переглядів: 14

Відео

2418 Sort the People
Переглядів 2614 години тому
2418 Sort the People. This Java code uses index sorting to return the names in tallest to shortest order. this is the psuedo code overview: We create an array of indices (0 to n-1). We sort these indices based on the heights in descending order. We use the sorted indices to create the result array with names in the correct order.
2392 Build a Matrix With Conditions
Переглядів 277 годин тому
2392 Build a Matrix With Conditions. This Java code solves the problem of building a k x k matrix that satisfies the given row and column conditions, we can break it down into the following steps: Topological Sorting: We need to perform topological sorting on the row conditions and column conditions separately. This will help us determine the order of elements in the rows and columns. Matrix Co...
1605 Find Valid Matrix Given Row and Column Sums
Переглядів 269 годин тому
1605 Find Valid Matrix Given Row and Column Sums. This Java code defines a class Solution with a method restoreMatrix that takes two integer arrays, rowSum and colSum, as input and returns a 2D matrix. The goal is to fill the matrix such that the sum of each row matches the corresponding value in rowSum and the sum of each column matches the corresponding value in colSum.
1530 Number of Good Leaf Nodes Pairs
Переглядів 1214 годин тому
1530 Number of Good Leaf Nodes Pairs
1110 Delete Nodes And Return Forest
Переглядів 816 годин тому
1110 Delete Nodes And Return Forest
2096 Step-By-Step Directions From a Binary Tree Node to Another
Переглядів 1919 годин тому
2096 Step-By-Step Directions From a Binary Tree Node to Another
726 Number of Atoms
Переглядів 36День тому
726 Number of Atoms
2751 Robot Collisions
Переглядів 27День тому
2751 Robot Collisions
1717 Maximum Score From Removing Substrings
Переглядів 7День тому
1717 Maximum Score From Removing Substrings
1190 Reverse Substrings Between Each Pair of Parentheses
Переглядів 77День тому
1190 Reverse Substrings Between Each Pair of Parentheses
1701 Average Waiting Time
Переглядів 3414 днів тому
1701 Average Waiting Time
1823 Find the Winner of the Circular Game Math Trick
Переглядів 1014 днів тому
1823 Find the Winner of the Circular Game Math Trick
1518 Water Bottles Math Trick
Переглядів 2114 днів тому
1518 Water Bottles Math Trick
1518 Water Bottles
Переглядів 2614 днів тому
1518 Water Bottles
2582 Pass the Pillow MathTrick
Переглядів 1714 днів тому
2582 Pass the Pillow MathTrick
2582 Pass the Pillow
Переглядів 47914 днів тому
2582 Pass the Pillow
2058 Find the Minimum and Maximum Number of Nodes Between Critical Points
Переглядів 714 днів тому
2058 Find the Minimum and Maximum Number of Nodes Between Critical Points
Let the Lass CryptoMath Brilliant 7 4 2024
Переглядів 714 днів тому
Let the Lass CryptoMath Brilliant 7 4 2024
2181 Merge Nodes in Between Zeros
Переглядів 1914 днів тому
2181 Merge Nodes in Between Zeros
1509 Minimum Difference Between Largest and Smallest Value in Three Moves
Переглядів 4321 день тому
1509 Minimum Difference Between Largest and Smallest Value in Three Moves
Operator Search Puzzle
Переглядів 4221 день тому
Operator Search Puzzle
1579 Remove Max Number of Edges to Keep Graph Fully Traversable
Переглядів 2121 день тому
1579 Remove Max Number of Edges to Keep Graph Fully Traversable
2192 All Ancestors of a Node in a Directed Acyclic Graph
Переглядів 1421 день тому
2192 All Ancestors of a Node in a Directed Acyclic Graph
2285 Maximum Total Importance of Roads
Переглядів 1721 день тому
2285 Maximum Total Importance of Roads
1038 Binary Search Tree to Greater Sum Tree
Переглядів 9328 днів тому
1038 Binary Search Tree to Greater Sum Tree
995 Minimum Number of K Consecutive Bit Flips
Переглядів 59Місяць тому
995 Minimum Number of K Consecutive Bit Flips
1438 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Переглядів 25Місяць тому
1438 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
1248 Count Number of Nice Subarrays
Переглядів 4Місяць тому
1248 Count Number of Nice Subarrays
1052 Grumpy Bookstore Owner
Переглядів 26Місяць тому
1052 Grumpy Bookstore Owner

КОМЕНТАРІ

  • @alec7568
    @alec7568 День тому

    This is pure cringe.

  • @sidharthbalakrishnan
    @sidharthbalakrishnan 2 дні тому

    This is not Java

  • @JabezJena
    @JabezJena Місяць тому

    Nice effort is applied in this video

  • @Ad-sn4up
    @Ad-sn4up Місяць тому

    Thanks 👍🏻

  • @Ad-sn4up
    @Ad-sn4up Місяць тому

    Thanks 👍🏻

  • @loutchyff6552
    @loutchyff6552 2 місяці тому

    I don't know what's this but lets go bro keep going 💪🏻

  • @matthewbaier766
    @matthewbaier766 3 місяці тому

    Ahh yes I do this all the time in the real world 💀

  • @ItsSuperMoosh
    @ItsSuperMoosh 3 місяці тому

    If you didnt use that cheap lazy ass AI voice over, you might not have needed 200 videos for 70 subs.

  • @ItsSuperMoosh
    @ItsSuperMoosh 3 місяці тому

    Piece of advice? Drop the lazy bullshit AI scripting and voice. Do your own shit. Be different. Not one of the million lazy shit ass yt pages ruining the platform.

  • @user-dr8sq9cn4h
    @user-dr8sq9cn4h 3 місяці тому

    Great Solution, Easy to understand and Optimal.

  • @alexeyrjeutski8147
    @alexeyrjeutski8147 4 місяці тому

    Right here there is no sense in double pointer technique. You can count the volume of the list first time, then get the middle in the second cycle - and it would be the same complexity. It would be the same amount of triggering of next pointers, the only advantage is in not adding the counter...

    • @nubunto
      @nubunto 4 місяці тому

      But you still iterate the list twice, right?

  • @kaninchengaming-inactive-6529
    @kaninchengaming-inactive-6529 4 місяці тому

    Smart!

  • @ziga1122
    @ziga1122 4 місяці тому

    why not just use a single while statement? As such: Node node = startNode; while (node.left != null) node = node.left

  • @n_x1891
    @n_x1891 5 місяців тому

    You should just subtract from tn instead of calculating the sum. You can also vectorize this operation.

    • @FogyFree
      @FogyFree 4 місяці тому

      Subtract what from tn or triangle number

    • @n_x1891
      @n_x1891 4 місяці тому

      @@FogyFree use the variable tn instead of sum. Subtracting in place is more efficient

  • @thefanboy3285
    @thefanboy3285 5 місяців тому

    god damn !

  • @hassankhan8055
    @hassankhan8055 5 місяців тому

    ❤❤❤

  • @Avneet098
    @Avneet098 5 місяців тому

    You can also do (n & -n) == n

    • @FogyFree
      @FogyFree 4 місяці тому

      I tried it and didn't pass test case 1 and 2

  • @Furryfattal
    @Furryfattal 5 місяців тому

    I wish spoken languages were like this. I've never wrote a lick of Java in my life but could understand this just fine 😂

  • @eterty8335
    @eterty8335 5 місяців тому

    que

  • @bruh-fw7op
    @bruh-fw7op 5 місяців тому

    as a computer engineering student, how the fuck did i never think of this

    • @FogyFree
      @FogyFree 4 місяці тому

      I'm not expert of binary but I consider this a trick or trivia that if you learn of it then you know the trick.

  • @Terrados1337
    @Terrados1337 5 місяців тому

    Neat, efficient code. But I'd probably slap you if I found that code uncommented in prod

    • @sorek__
      @sorek__ 5 місяців тому

      This is good code that doesn't need comments. Comment is in the name, rest you read and just understand as you go along.

    • @vibaj16
      @vibaj16 5 місяців тому

      I'm more annoyed at that curly bracket placement

    • @bruh-fw7op
      @bruh-fw7op 5 місяців тому

      @@vibaj16 that is the superior curly bracket placement

    • @vibaj16
      @vibaj16 5 місяців тому

      @@bruh-fw7op nooooo

    • @OnFireByte
      @OnFireByte 5 місяців тому

      ​@@sorek__ I agree that function's name should be enough for conveying what's trying to do, which it is. But it's just that there should be a comment why it work in the code that do some hacky stuff especially bitwise genius.

  • @clrkgmii
    @clrkgmii 5 місяців тому

    holy shit

  • @user-bt5ot8iv3m
    @user-bt5ot8iv3m 5 місяців тому

    Nice

  • @user-bt5ot8iv3m
    @user-bt5ot8iv3m 5 місяців тому

    ❤❤❤❤❤❤

  • @BattlewarPenguin
    @BattlewarPenguin 5 місяців тому

    'For we live by faith, not by sight.'

  • @WillEhrendreich
    @WillEhrendreich 6 місяців тому

    Wait.. How is this any different than simply being an anagram?

    • @FogyFree
      @FogyFree 4 місяці тому

      anagram has more symmetry, you can look up problem 1657 on leetcode for full description

  • @FogyFree
    @FogyFree 6 місяців тому

    1235 Maximum Profit in Job Scheduling. To solve the problem of finding the maximum profit in job scheduling without overlapping time ranges, we can use dynamic programming. The idea is to sort the jobs by their end times and then iterate through the sorted jobs, at each step calculating the maximum profit that can be obtained by either taking the current job or not. This code defines a Job class to store the start time, end time, and profit of a job. The jobScheduling method first creates an array of Job objects and sorts them by their end times. It then uses dynamic programming to calculate the maximum profit at each step, storing the results in the dp array. The findLastNonConflictingJob method is a binary search helper function that finds the last job that does not conflict with the current job being considered. The time complexity of this solution is O(n log n) due to the sorting step and the binary search for each job. The space complexity is O(n) for the dp array and the jobs array. Here's a Java implementation of the solution: java import java.util.Arrays; class Solution { public int jobScheduling(int[] startTime, int[] endTime, int[] profit) { int n = startTime.length; Job[] jobs = new Job[n]; for (int i = 0; i < n; i++) { jobs[i] = new Job(startTime[i], endTime[i], profit[i]); } // Sort the jobs by their end time Arrays.sort(jobs, (a, b) -> a.end - b.end); // dp[i] will store the maximum profit by considering jobs[0...i] int[] dp = new int[n]; dp[0] = jobs[0].profit; for (int i = 1; i < n; i++) { // Profit including the current job int profitIncluding = jobs[i].profit; int lastIndex = findLastNonConflictingJob(jobs, i); if (lastIndex != -1) { profitIncluding += dp[lastIndex]; } // Maximum profit by excluding or including the current job dp[i] = Math.max(dp[i - 1], profitIncluding); } // The last element of dp will have the maximum profit return dp[n - 1]; } // Helper method to find the last job which doesn't conflict with the current job private int findLastNonConflictingJob(Job[] jobs, int index) { int low = 0, high = index - 1; while (low <= high) { int mid = (low + high) / 2; if (jobs[mid].end <= jobs[index].start) { if (jobs[mid + 1].end <= jobs[index].start) { low = mid + 1; } else { return mid; } } else { high = mid - 1; } } return -1; } // Job class to store the start time, end time, and profit of a job class Job { int start, end, profit; public Job(int start, int end, int profit) { this.start = start; this.end = end; this.profit = profit; } } }

  • @bertieraisin8250
    @bertieraisin8250 6 місяців тому

    🌸 'PromoSM'