question_slug stringlengths 3 77 | title stringlengths 1 183 | slug stringlengths 12 45 | summary stringlengths 1 160 ⌀ | author stringlengths 2 30 | certification stringclasses 2
values | created_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | updated_at stringdate 2013-10-25 17:32:12 2025-04-12 09:38:24 | hit_count int64 0 10.6M | has_video bool 2
classes | content stringlengths 4 576k | upvotes int64 0 11.5k | downvotes int64 0 358 | tags stringlengths 2 193 | comments int64 0 2.56k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
maximum-frequency-after-subarray-operation | Beats 100% Java | beats-100-java-by-alansuncomet2-06jv | IntuitionProblem basically is trying to find the largest subarray of one specific element - the number of ks in the subarray.ApproachReminded me of Kadanes with | alansuncomet2 | NORMAL | 2025-01-26T04:31:21.409227+00:00 | 2025-01-26T04:31:21.409227+00:00 | 207 | false | # Intuition
Problem basically is trying to find the largest subarray of one specific element - the number of ks in the subarray.
# Approach
Reminded me of Kadanes with a counting approach.
# Complexity
- Time complexity:
O(n)
- Space complexity:
O(1)
# Code
```java []
class Solution {
public int maxFrequency(i... | 2 | 0 | ['Greedy', 'Java'] | 0 |
maximum-frequency-after-subarray-operation | Maximum Subarray Sum | maximum-subarray-sum-by-wanderingcicada-ug9v | IntuitionTry every number other than k.For example, if k = 2 and we have [1, 2, 2, 2, 1, 1, 2, 1, 3, 3, 3], try to turn 1s into 2 and try to turn 3's into 2Appr | wanderingCicada | NORMAL | 2025-01-26T04:16:06.316443+00:00 | 2025-01-26T04:16:06.316443+00:00 | 230 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Try every number other than k.
For example, if k = 2 and we have [1, 2, 2, 2, 1, 1, 2, 1, 3, 3, 3], try to turn 1s into 2 and try to turn 3's into 2
# Approach
<!-- Describe your approach to solving the problem. -->
What is the problem o... | 2 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Using HashMap to try all numbers | using-hashmap-to-try-all-numbers-by-minh-y18a | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | minh_nhut | NORMAL | 2025-01-26T04:05:52.347140+00:00 | 2025-01-26T04:05:52.347140+00:00 | 581 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Java'] | 2 |
maximum-frequency-after-subarray-operation | Easy Javascript Solution || Beats 100% || Simple Explanation Provided || Leetcode Contest 434 || | easy-javascript-solution-beats-100-simpl-r4yt | IntuitionThe code calculates the maximum possible frequency of the number k after applying an optimal shift value x to the elements of nums[]. It finds the maxi | Abhyanand_Sharma | NORMAL | 2025-01-26T04:05:21.017807+00:00 | 2025-01-26T04:24:28.956527+00:00 | 181 | false | # Intuition
The code calculates the maximum possible frequency of the number `k` after applying an optimal shift value `x` to the elements of `nums[]`. It finds the maximum gain in frequency by adjusting each element and evaluates the best possible shift.<!-- Describe your first thoughts on how to solve this problem. -... | 2 | 0 | ['Array', 'Hash Table', 'Dynamic Programming', 'Greedy', 'Prefix Sum', 'JavaScript'] | 3 |
maximum-frequency-after-subarray-operation | [Python3] max diff | python3-max-diff-by-ye15-skja | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ye15 | NORMAL | 2025-01-26T04:03:27.070435+00:00 | 2025-01-26T04:03:27.070435+00:00 | 302 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 2 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Kadane's like wise | kadanes-like-wise-by-sohailalamx-h9bi | Intuitionkadane's algoApproachComplexity
Time complexity: O(n*50)
Space complexity: O(n*50)
Code | sohailalamx | NORMAL | 2025-02-01T18:19:25.693264+00:00 | 2025-02-01T18:19:25.693264+00:00 | 22 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
kadane's algo
# Approach
<!-- Describe your approach to solving the problem. -->
- divide the given array into chuncks dividers are the
position of kl
- keep the frequency of 1 to 50 in between ks
- take each element and p... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Single Pass Java Solution | Beats 100% | java-beats-100-by-samyu1997-tcd6 | IntuitionTo solve this problem, we need to understand the effect of converting a value in a subarray to k. Specifically, converting a given value in a subarray | samyu1997 | NORMAL | 2025-01-31T07:49:12.470193+00:00 | 2025-01-31T08:01:23.624113+00:00 | 13 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
To solve this problem, we need to understand the effect of converting a value in a subarray to k. Specifically, converting a given value in a subarray to k means all occurrences of k in that subarray will be transformed into a different val... | 1 | 0 | ['Array', 'Hash Table', 'Dynamic Programming', 'Greedy', 'Java'] | 1 |
maximum-frequency-after-subarray-operation | [C++] | c-by-bora_marian-ac30 | The testcase that helped:
[1, 3, 1, 9, 9, 4, 1] and k = 1 -> should output 5: explanation we take all the elements equals to 1 and then for [3, 5] we add -8.
We | bora_marian | NORMAL | 2025-01-29T20:23:57.730276+00:00 | 2025-01-29T20:23:57.730276+00:00 | 45 | false | The testcase that helped:
- [1, 3, 1, 9, 9, 4, 1] and k = 1 -> should output 5: explanation we take all the elements equals to 1 and then for [3, 5] we add -8.
- We can explore the idea that we need other elements and see how they contribute to existing frequency of k. If we take 9 as example: we make the elements of n... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | tabular dp on each possible x | tabular-dp-on-each-possible-x-by-joshuad-z97h | Intuitionstatus: 0, 1, 2
0 -> we havent taken a subarray yet => we can either continue without taking or decide to take it from this index.1 -> we are currently | joshuadlima | NORMAL | 2025-01-28T12:59:01.759374+00:00 | 2025-01-28T13:10:10.886810+00:00 | 22 | false | # Intuition
status: 0, 1, 2
0 -> we havent taken a subarray yet => we can either continue without taking or decide to take it from this index.
1 -> we are currently taking a subarray => we can either continue taking the subarray or stop taking it.
2 -> we have completed the subarray => we can only go on since only on... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | I laugh at all those mention Kadane and having a O(nm) solution. This is really O(n) DP. | i-laugh-at-all-those-mention-kadane-and-nmjnm | IntuitionTried to using template is sometimes good but it limit your creativity.This is simply O(n) DP, no loopping through 1-50. The numbers can be in any rang | leokan | NORMAL | 2025-01-27T02:28:54.774863+00:00 | 2025-01-27T02:28:54.774863+00:00 | 73 | false | # Intuition
Tried to using template is sometimes good but it limit your creativity.
This is simply O(n) DP, no loopping through 1-50. The numbers can be in any range it doesn't matter.
We are really finding the array nums[i..j] with most number occurancy plus most of k outside of this range.
# Approach
let
$$f(i) ... | 1 | 0 | ['Python3'] | 1 |
maximum-frequency-after-subarray-operation | Fastest there is✅0ms || 100% || optimized🔥💯🚀 | fastest-there-is0ms-100-optimized-by-zab-ws7a | Complexity :
Time complexity: O(n)
Space complexity: $O(1)
Code : | zabakha | NORMAL | 2025-01-26T20:55:06.824590+00:00 | 2025-01-26T20:55:06.824590+00:00 | 27 | false | 
---
# Complexity :
- Time complexity: $O(n)$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $O(1)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
---
# Code :
```cpp []... | 1 | 0 | ['Counting', 'C++'] | 0 |
maximum-frequency-after-subarray-operation | [Python3] Max Frequency Diff with explanation | python3-max-diff-with-explanation-by-ked-1ov0 | IntuitionThe original solution is from
https://leetcode.com/problems/maximum-frequency-after-subarray-operation/solutions/6329906/simplest-python-solution-o-50- | keda626new | NORMAL | 2025-01-26T17:01:12.374817+00:00 | 2025-01-26T17:07:00.641137+00:00 | 54 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The original solution is from
https://leetcode.com/problems/maximum-frequency-after-subarray-operation/solutions/6329906/simplest-python-solution-o-50-n-try-all-numbers-only/
Thanks to @112115046 for sharing it.
The basic idea is to find a... | 1 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Kadane O(n) Soln || Commented Code | kadane-on-soln-commented-code-by-ammar-a-tbch | Complexity
Time complexity: O(n)
Space complexity: O(1)
Code | ammar-a-khan | NORMAL | 2025-01-26T16:23:15.142052+00:00 | 2025-01-26T16:23:15.142052+00:00 | 83 | false | # Complexity
- Time complexity: $O(n)$
- Space complexity: $O(1)$
# Code
```cpp
int maxFrequency(vector<int> &nums, int k){
int kFreq = 0; //stores net freq of k
for (int i = 0; i < nums.size(); ++i){ if (nums[i] == k){ ++kFreq; } }
int maxFreq = 0; //stores maxFreq found
for (int val = 1; val <= 50; +... | 1 | 0 | ['Counting', 'C++'] | 0 |
maximum-frequency-after-subarray-operation | Beginner friendly soln. | beginner-friendly-soln-by-peeyush_thakur-bfpd | IntuitionApproachComplexity
Time complexity: O(50*N)
Space complexity:O(N)
Code | peeyush_thakur | NORMAL | 2025-01-26T12:15:57.212028+00:00 | 2025-01-26T12:15:57.212028+00:00 | 85 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: O(50*N)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(N)
<!-- Add your space complexity here, e.g. $$O(n)$$ -... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Simple Solution | simple-solution-by-prince_kumar1-9am7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | prince_kumar1 | NORMAL | 2025-01-26T11:46:37.947018+00:00 | 2025-01-26T11:46:37.947018+00:00 | 24 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 1 | 0 | ['Java'] | 0 |
maximum-frequency-after-subarray-operation | soution using kadan's algorithm with Time complaity-->O(n) space complaxity-->O(1) | soution-using-kadans-algorithm-with-time-bckx | IntuitionThe intuition is straightforward: we need to find the maximum frequency of
k by performing one operation on a subarray. This can be efficiently achieve | Nikhil-error | NORMAL | 2025-01-26T11:26:26.737788+00:00 | 2025-01-29T08:56:39.960040+00:00 | 60 | false | # Intuition
The intuition is straightforward: we need to find the maximum frequency of
k by performing one operation on a subarray. This can be efficiently achieved using Kadane's algorithm...
# Approach
First, we count the occurrences of in the given array. Since the constraints ensure 1<=nums[i]<=50 we can iterate th... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Kadane's Algorithm | kadanes-algorithm-by-varun_cns-qhaq | Summary of the Algorithm's Purpose
The algorithm is designed to find the maximum frequency of any element in the array after performing up to k increment operat | varun_cns | NORMAL | 2025-01-26T11:22:25.713889+00:00 | 2025-01-26T11:22:25.713889+00:00 | 20 | false | # Summary of the Algorithm's Purpose
- The algorithm is designed to find the maximum frequency of any element in the array after performing up to k increment operations on subarrays.
- It iterates over possible target values (1 to 50), calculates how many times a subarray can be converted into that value by applying th... | 1 | 0 | ['Python'] | 0 |
maximum-frequency-after-subarray-operation | PLEASE UPVOTE THE SOLUTION | please-upvote-the-solution-by-sojwalvilh-7r3j | Intuitionfind the largest freq of target element in range 1-50ApproachKadanes Algo for all the possible target in range 1-50Complexity
Time complexity:
O(50n) | the-Code-Monk | NORMAL | 2025-01-26T07:58:36.709761+00:00 | 2025-01-26T07:58:36.709761+00:00 | 15 | false | # Intuition
find the largest freq of target element in range 1-50
# Approach
Kadanes Algo for all the possible target in range 1-50
# Complexity
- Time complexity:
O(50n)
- Space complexity:
O(1)
# Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
int k_s = 0... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | KADANE's ALGO | kadanes-algo-by-sourav19-zdof | IntuitionApproachComplexity
Time complexity:O(N*K)
Space complexity:O(N*K)
Code | Sourav19 | NORMAL | 2025-01-26T06:43:11.634459+00:00 | 2025-01-26T06:43:11.634459+00:00 | 21 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:O(N*K)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:O(N*K)
<!-- Add your space complexity here, e.g. $$O(n)$$ -... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Easy to understand memoised DP code | easy-to-understand-memoised-dp-code-by-h-ezqo | IntuitionHow is this a DP problem? Well, we have to find the maximum frequency of the element k given that we are allowed to modify a subarray by adding or subt | harshsri1602 | NORMAL | 2025-01-26T05:57:57.228949+00:00 | 2025-01-26T05:57:57.228949+00:00 | 231 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
How is this a DP problem? Well, we have to find the maximum frequency of the element k given that we are allowed to modify a subarray by adding or subtracting a constant number. So , we will have to try this out with all possible subarrays.... | 1 | 0 | ['Dynamic Programming', 'C++'] | 1 |
maximum-frequency-after-subarray-operation | SLIDING WINDOW || SIMPLEST | sliding-window-simplest-by-shivbh321-d4hp | Intuitionso if nums[i] == 50 and k==1 so u have to subtract 49
and if nums[i]==1 and k==50 so you have to add 49 that's why from -50 to 50Approachcount the ini | shivbh321 | NORMAL | 2025-01-26T05:46:23.005880+00:00 | 2025-01-26T05:46:23.005880+00:00 | 183 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
What can be the value of x?
only from -50 to 50 but why? because nums contains values from only 1 to 50.
so if nums[i] == 50 and k==1 so u have to subtract 49
and if nums[i]==1 and k==50 so you have to add 49 that's why from -... | 1 | 0 | ['C++'] | 1 |
maximum-frequency-after-subarray-operation | Java Real O(n) 100% PrefixCount Solution | No Nested Loop | java-simple-linear-time-100-prefixcount-bu9zl | IntuitionAt each index j, we need to find index i such that valuecan be maximised
Then iterate across all indices j of nums to find the resultApproachComplexity | akandak | NORMAL | 2025-01-26T05:37:18.224260+00:00 | 2025-01-27T08:02:29.946192+00:00 | 124 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
At each index `j`, we need to find index `i` such that value
```
{
1. num of ks in [0..i-1] +
2. max freq of any char that we want to convert to k in subarray [i..j] +
3. num of ks in [j+1...last]
}
```
can be maximised
Then iterate acr... | 1 | 0 | ['Prefix Sum', 'Java'] | 0 |
maximum-frequency-after-subarray-operation | Simple Solution || Kadane's || easy to understand. | simple-solution-kadanes-easy-to-understa-11zd | Approachsolved this after hints
just as they say fix any nums[i].
compute the contribution of nums[i] to ans frequency in O(n).
just read inline commments you | naveen_gunnam | NORMAL | 2025-01-26T05:10:47.695717+00:00 | 2025-01-26T05:10:47.695717+00:00 | 59 | false |
# Approach
<!-- Describe your approach to solving the problem. -->
solved this after hints
just as they say fix any nums[i].
compute the contribution of nums[i] to ans frequency in O(n).
just read inline commments you will get it.
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ --... | 1 | 0 | ['Java'] | 1 |
maximum-frequency-after-subarray-operation | Python Solution | Prefix sums O(n), Beats 100% in Contest | python-solution-prefix-sums-on-beats-100-ren0 | ApproachWe want to find the interval at which to apply the operation. If the interval is over a subarray where k does not occur, then the mode of that subarray | vincentcai70 | NORMAL | 2025-01-26T05:09:04.779189+00:00 | 2025-01-26T05:09:40.027906+00:00 | 148 | false | # Approach
We want to find the interval at which to apply the operation. If the interval is over a subarray where k does not occur, then the mode of that subarray is added to the final result. However, if there are occurences of k in that interval, and the mode is not k in that interval, than those occurences of k will... | 1 | 0 | ['Hash Table', 'Prefix Sum', 'Python3'] | 1 |
maximum-frequency-after-subarray-operation | Easy Beginner friendly || Java || Python || C++ | easy-beginner-friendly-java-python-c-by-7g5ax | Complexity
Time complexity:
O(50*n) - for loop
Overall O(n)
Space complexity:
O(1)
Code | Akshay_Kadamm | NORMAL | 2025-01-26T05:02:46.680516+00:00 | 2025-01-26T05:02:46.680516+00:00 | 145 | false | # Complexity
- Time complexity:
O(50*n) - for loop
#### Overall O(n)
- Space complexity:
O(1)
# Code
```java []
class Solution {
public int maxFrequency(int[] nums, int k) {
int Ktotal = 0;
for (int num : nums) {
if (num == k) {
Ktotal++;
}
}
... | 1 | 0 | ['Python', 'C++', 'Java'] | 0 |
maximum-frequency-after-subarray-operation | Try all numbers | try-all-numbers-by-optimizor-c0cu | Code | Optimizor | NORMAL | 2025-01-26T04:42:53.888271+00:00 | 2025-01-26T04:42:53.888271+00:00 | 95 | false | # Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
int tk = 0;
for (auto it : nums) {
if (it == k) {
tk++;
}
}
int maxi = 0;
for (int i = 1; i <= 50; i++) {
if (i == k && 1) continue;
... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | loop on x and some state transitions between 3 states | loop-on-x-and-some-state-transitions-bet-kpbd | Code | nishsolvesalgo | NORMAL | 2025-01-26T04:31:50.535945+00:00 | 2025-01-26T04:31:50.535945+00:00 | 16 | false | # Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
int maxFreq = 0;
for(int x=-51; x<52; x++){
int KwithoutModifying = 0, KwithModifying = 0, Kmodified = 0;
for(int i=0; i<nums.size(); i++){
int modified = nums[i] + x;
... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Best Solution ||Beats 100%||Why kadane Algorithm|| O(n)||C++||java||python | best-solution-beats-100why-kadane-algori-rbk3 | IntuitionWhenever maximum sum probelm give atleast one view to kadane algorithm as it does a thing ino(n) complexityApproachMy approach is simple.we have to max | Da_btc | NORMAL | 2025-01-26T04:16:01.799034+00:00 | 2025-01-26T04:16:01.799034+00:00 | 48 | false | # Intuition
Whenever maximum sum probelm give atleast one view to kadane algorithm as it does a thing ino(n) complexity
# Approach
My approach is simple.
we have to maximize the subarray size from which a number to be subtrcted then we will define k-nums[i] as the number to be decreased by thus make a set to store **... | 1 | 0 | ['Python', 'C++', 'Java'] | 0 |
maximum-frequency-after-subarray-operation | Trying out all differences and Getting the most Optimal Out of IT | trying-out-all-differences-and-getting-t-zmk8 | IntuitionAs we know there is a specific and if in constraints we are given num[i] ranges from 1 to 50 we can check for all differences we get from k-nums[i] | thewizard641 | NORMAL | 2025-01-26T04:10:52.621801+00:00 | 2025-01-26T04:10:52.621801+00:00 | 189 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
As we know there is a specific and if in constraints we are given num[i] ranges from 1 to 50 we can check for all differences we get from k-nums[i] as one of the diff is the main hero of this short story which will help to get out the ma... | 1 | 1 | ['Array', 'Hash Table', 'Prefix Sum', 'C++'] | 1 |
maximum-frequency-after-subarray-operation | Kadane's Algorithm / Change each number into K | change-each-number-into-k-by-cinderace-tafv | IntuitionThe idea is similar conceptually to Kadane's algorithm - we test each number, and attempt to create a subarray with a maximum "score" by converting eac | cinderace | NORMAL | 2025-01-26T04:08:20.174974+00:00 | 2025-01-26T04:16:36.112889+00:00 | 182 | false | # Intuition
The idea is similar conceptually to Kadane's algorithm - we test each number, and attempt to create a subarray with a maximum "score" by converting each occurence of this number to K. Each time we find the number we're testing, we add 1 point. If we find "K", we subtract one point. If this score is negative... | 1 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Simplest solution || Beginner friendly || Best time complexity | simplest-solution-beginner-friendly-best-j6gw | Approach
Count the initial occurrences of k.
Iterate over all possible values v (1 to 50) except k.
Find the best subarray where we can transform v to k using o | RayugaMaxx | NORMAL | 2025-01-26T04:05:14.948164+00:00 | 2025-01-26T04:05:14.948164+00:00 | 122 | false |
# Approach
<!-- Describe your approach to solving the problem. -->
1. Count the initial occurrences of k.
2. Iterate over all possible values v (1 to 50) except k.
3. Find the best subarray where we can transform v to k using one operation.
4. Keep track of the maximum gain in the number of ks.
5. Return the sum of t... | 1 | 0 | ['C++'] | 1 |
maximum-frequency-after-subarray-operation | Suffix sum + frequency array | suffix-sum-frequency-array-by-jkulanko-m4ws | IntuitionCreate a suffix sum counting number of k's in the array. Then iterate through the array and at each index increment frequency by one and decrement by | jkulanko | NORMAL | 2025-01-26T04:02:29.984424+00:00 | 2025-01-26T04:05:30.051197+00:00 | 309 | false | # Intuition
Create a suffix sum counting number of k's in the array. Then iterate through the array and at each index increment frequency by one and decrement by the number of k's since the last time you saw the number.
# Complexity
- Time complexity:
$$O(50n)$$
# Code
```cpp []
class Solution {
public:
int max... | 1 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Mathematical Proof + Video Explanation | Prefix Sum trick | C++ | mathematical-proof-video-explanation-pre-83eg | IntuitionPrefix Sums and brute forceApproachCode | saber2k18 | NORMAL | 2025-01-26T04:02:28.611441+00:00 | 2025-01-26T04:02:28.611441+00:00 | 386 | false | # Intuition
Prefix Sums and brute force
# Approach
https://www.youtube.com/watch?v=hRI2XerqxT4
# Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
int n = nums.size();
int ans = 0;
for(int e=1;e<=50;++e){
vector<int> v;
for(int j=... | 1 | 0 | ['C++'] | 1 |
maximum-frequency-after-subarray-operation | Easy Approach using C++ | easy-approach-using-c-by-vaibhav_8101-v72n | IntuitionSo as we have to find the max number of element equal to target ,we can get after performing the operation on the subarray, one way is to make all the | vaibhav_8101 | NORMAL | 2025-03-07T18:36:50.297985+00:00 | 2025-03-07T18:36:50.297985+00:00 | 5 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
So as we have to find the max number of element equal to target ,we can get after performing the operation on the subarray, one way is to make all the subarray and check how many element you can make equal to k, but we will get TLE because ... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | C++ | Kadane | c-kadane-by-kena7-lxsn | Code | kenA7 | NORMAL | 2025-02-25T05:55:28.842302+00:00 | 2025-02-25T05:55:28.842302+00:00 | 4 | false |
# Code
```cpp []
class Solution {
public:
int find(int change,int k, vector<int>& nums)
{
int kc=0;
for(auto &x:nums)
kc+=(x==k);
if(change==k)
return kc;
int res=kc,curr=0;
for(auto &x:nums)
{
if(x==change)
curr+... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Only calculate the delta and transform it to longest sum subarray. | only-calculate-the-delta-and-transform-i-hvkz | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | labao | NORMAL | 2025-02-24T16:12:13.093328+00:00 | 2025-02-24T16:12:13.093328+00:00 | 2 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Java'] | 0 |
maximum-frequency-after-subarray-operation | [C++] Kadane for Each Value in Range, 100% Space (0ms), ~98% Space (96.33MB) | c-kadane-for-each-value-in-range-100-spa-vwws | This problem can be solved by figuring out that:
on one hand, we have the natural occurrences of values in nums already matching k;
on the other hand, having mu | Ajna2 | NORMAL | 2025-02-15T11:01:04.286550+00:00 | 2025-02-15T11:01:04.286550+00:00 | 16 | false | This problem can be solved by figuring out that:
* on one hand, we have the natural occurrences of values in `nums` already matching `k`;
* on the other hand, having multiple repeated values in a given interval can mean more matches, even if we alter some of the natural occurrences, since we can take all the values in ... | 0 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'C++'] | 0 |
maximum-frequency-after-subarray-operation | scala twoliner | scala-twoliner-by-vititov-lud6 | null | vititov | NORMAL | 2025-02-13T18:15:38.553133+00:00 | 2025-02-13T18:15:38.553133+00:00 | 4 | false | ```scala []
object Solution {
def maxFrequency(nums: Array[Int], k: Int): Int = {
val nMap = nums.groupMapReduce(identity)(_ => 1)(_ + _)
nMap.keysIterator.filterNot(_ == k).map{num0 =>
nums.iterator.scanLeft((0,0)){case (inp@(kCnt1,nCnt),num) =>
if(num==num0) (kCnt1,nCnt+1)
else if(num=... | 0 | 0 | ['Hash Table', 'Greedy', 'Prefix Sum', 'Scala'] | 0 |
maximum-frequency-after-subarray-operation | Easy Python Solution | easy-python-solution-by-sb012-bn2v | Code | sb012 | NORMAL | 2025-02-07T23:28:22.271000+00:00 | 2025-02-07T23:28:22.271000+00:00 | 8 | false | # Code
```python3 []
class Solution:
def maxFrequency(self, nums: List[int], k: int) -> int:
answer = 0
for i in range(1, 50 + 1):
if i == k:
continue
maxi = 0
curr = 0
for j in nums:
if j == i:
cur... | 0 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Javascript | Kandane | O(n) | javascript-kandane-on-by-aryonbe-wdw3 | Code | aryonbe | NORMAL | 2025-02-07T07:51:06.116077+00:00 | 2025-02-07T07:51:06.116077+00:00 | 7 | false | # Code
```javascript []
/**
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
var maxFrequency = function(nums, k) {
const count = new Map();
for(let num of nums){
count.set(num, (count.get(num) || 0) + 1);
}
let kandane = (b)=>{
let cur = 0;
for(let num of n... | 0 | 0 | ['JavaScript'] | 0 |
maximum-frequency-after-subarray-operation | Java Simple Solution with Kadane's Algo || simple || easy code | java-simple-solution-with-kadanes-algo-s-liyi | IntuitionSo here we need to understand how Kadane's algorithm is working here so in this problem we need to actually find out the maximum frequency after survey | palindrome_kasak | NORMAL | 2025-02-06T11:31:28.248068+00:00 | 2025-02-06T11:31:28.248068+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
So here we need to understand how Kadane's algorithm is working here so in this problem we need to actually find out the maximum frequency after survey operations so when we see Subarray and we want to take out a subarray and make a operati... | 0 | 0 | ['Array', 'Hash Table', 'Java'] | 0 |
maximum-frequency-after-subarray-operation | Using the kadanes algorithm | using-the-kadanes-algorithm-by-dyaganikh-ywdp | Intuitionselect the subarray which in which the maximum frequent element is present
add the frequency of the element k and the count of maximum frequent element | dyaganikhil | NORMAL | 2025-02-06T09:26:19.747725+00:00 | 2025-02-06T09:26:19.747725+00:00 | 8 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->count the number of elements which are k
select the subarray which in which the maximum frequent element is present
add the frequency of the element k and the count of maximum frequent element.
# Approach
<!-- Describe your approach to solv... | 0 | 0 | ['Array', 'Prefix Sum', 'C++'] | 0 |
maximum-frequency-after-subarray-operation | Kadane's Algorithm approach [C++/Java/Python] || Beats 100% | kadanes-algorithm-approach-cjavapython-b-y0pj | This question is based on use of kadane's algorithmKadane's Algorithm
Kadane’s algorithm typically solves the maximum subarray sum problem by maintaining:
A cur | be_fighter | NORMAL | 2025-02-04T20:05:49.138011+00:00 | 2025-02-04T20:05:49.138011+00:00 | 21 | false | This question is based on use of kadane's algorithm
# Kadane's Algorithm
1. Kadane’s algorithm typically solves the maximum subarray sum problem by maintaining:
2. A current sum that represents the best sum ending at the current element.
3. A global maximum that stores the best sum found so far.
4. The key insight is ... | 0 | 0 | ['Array', 'Hash Table', 'Math', 'Dynamic Programming', 'Greedy', 'Prefix Sum', 'Python', 'C++', 'Java', 'JavaScript'] | 0 |
maximum-frequency-after-subarray-operation | lets View it as a dynammic programming problem which ends at j but in a different way | lets-view-it-as-a-dynammic-programming-p-yxgv | IntuitionIn this problem, we want to maximize the occurrences of k. A key observation is that the same elements will contribute the same value when transformed | aspiringgarv | NORMAL | 2025-01-31T06:37:24.242644+00:00 | 2025-01-31T06:37:24.242644+00:00 | 4 | false | # Intuition
In this problem, we want to maximize the occurrences of `k`. A key observation is that the same elements will contribute the same value when transformed into `k`.
Thus, we can **group occurrences of the same element** and use these indices as potential start and end points for our subarrays.
# Approach
#... | 0 | 0 | ['Java'] | 0 |
maximum-frequency-after-subarray-operation | Heap Solution | Python | heap-solution-python-by-cholebhature-xbj8 | Complexity
Time complexity:
O(nlogn)
Space complexity:
O(n)
Code | cholebhature | NORMAL | 2025-01-30T10:08:16.051076+00:00 | 2025-01-30T10:08:16.051076+00:00 | 11 | false |
# Complexity
- Time complexity:
$$O(nlogn)$$
- Space complexity:
$$O(n)$$
# Code
```python3 []
class Solution:
def maxFrequency(self, nums: List[int], k: int) -> int:
n = len(nums)
t = 0
for i in nums:
if i != k:
t = 1
break
... | 0 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Using simple maximum subarray sum kadence algo | using-simple-maximum-subarray-sum-kadenc-5i0x | Using simple maximum subarray sum kadence algoCode | rthakur2712 | NORMAL | 2025-01-30T09:58:03.648464+00:00 | 2025-01-30T09:58:03.648464+00:00 | 16 | false | Using simple maximum subarray sum kadence algo
# Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& a, int k) {
int n = int(a.size());
int m = *max_element(a.begin(), a.end());
int maxi_ans = 0;
int cnt=0;
for(int i=0; i<n; i++){
if( a[i] == k )... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Easiest organic approach || O(50*N) | easiest-organic-approach-o50n-by-seriall-btzf | Intuition/ApproachIdea is to first bucketise each partition and calculate the frequency of each number for each bucket.
Then run the helper function for each po | seriallazer | NORMAL | 2025-01-29T12:21:52.934178+00:00 | 2025-01-29T12:24:11.530746+00:00 | 9 | false | # Intuition/Approach
<!-- Describe your first thoughts on how to solve this problem. -->
Idea is to first bucketise each partition and calculate the frequency of each number for each bucket.
Then run the helper function for each possible number with this bucketised frequency list to get the subarray that maximises
Last... | 0 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Maximum Frequency After Subarray Operation | maximum-frequency-after-subarray-operati-z12e | Code | Ansh1707 | NORMAL | 2025-01-29T03:35:47.307104+00:00 | 2025-01-29T03:35:47.307104+00:00 | 7 | false |
# Code
```python []
class Solution(object):
def maxFrequency(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: int
"""
original_count = nums.count(k)
n = len(nums)
def kadane(arr):
max_current = max_global = arr[0]
... | 0 | 0 | ['Python'] | 0 |
maximum-frequency-after-subarray-operation | Kadane's | kadanes-by-srptv-juox | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | srptv | NORMAL | 2025-01-29T02:33:00.081927+00:00 | 2025-01-29T02:33:00.081927+00:00 | 8 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Maximum Frequency After Subarray Operations || Java Solution | maximum-frequency-after-subarray-operati-pwkz | IntuitionThe problem for the maximum frequency of any number in the array after potentially modifying some of the values. Modifications can be done by changing | pawan_leel | NORMAL | 2025-01-28T18:47:40.267658+00:00 | 2025-01-28T18:47:40.267658+00:00 | 14 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The problem for the maximum frequency of any number in the array after potentially modifying some of the values. Modifications can be done by changing some numbers to the number `k`, which is given. This means that if we can maximize how ma... | 0 | 0 | ['Java'] | 0 |
maximum-frequency-after-subarray-operation | dynamic programming || prefix map|| suffix map || o(n*50) ||c ++ | dynamic-programming-prefix-map-suffix-ma-s6ow | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | sarthakrautelanew | NORMAL | 2025-01-28T17:13:52.815194+00:00 | 2025-01-28T17:13:52.815194+00:00 | 33 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-frequency-after-subarray-operation | Simple Java Solution | simple-java-solution-by-sakshikishore-6rrl | Code | sakshikishore | NORMAL | 2025-01-28T12:21:06.409452+00:00 | 2025-01-28T12:21:06.409452+00:00 | 12 | false | # Code
```java []
class Solution {
public int maxFrequency(int[] nums, int k) {
int pref[] = new int[nums.length];
int sum = 0;
HashSet<Integer> hset = new HashSet<Integer>();
for (int i = 0; i < nums.length; i++) {
if (nums[i] == k) {
sum += 1;
... | 0 | 0 | ['Java'] | 0 |
maximum-frequency-after-subarray-operation | memoisation for each valid x | memoisation-for-each-valid-x-by-joshuadl-075c | Intuitionstatus: 0, 1, 2
0 -> we havent taken a subarray yet => we can either continue without taking or decide to take it from this index.1 -> we are currently | joshuadlima | NORMAL | 2025-01-28T12:19:42.670076+00:00 | 2025-01-28T13:10:37.587177+00:00 | 4 | false | # Intuition
status: 0, 1, 2
0 -> we havent taken a subarray yet => we can either continue without taking or decide to take it from this index.
1 -> we are currently taking a subarray => we can either continue taking the subarray or stop taking it.
2 -> we have completed the subarray => we can only go on since only on... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | modified Kadane's algo. | modified-kadanes-algo-by-rishiinsane-in3h | IntuitionWe need to maximize the frequency of any element in the array after transforming some occurrences of the given element k into other values. Observe tha | RishiINSANE | NORMAL | 2025-01-28T09:49:31.822209+00:00 | 2025-01-28T09:49:31.822209+00:00 | 18 | false | # Intuition
We need to maximize the frequency of any element in the array after transforming some occurrences of the given element k into other values. Observe that the transformation from k to any other element can be thought of as a sliding window or subarray problem, where we try to accumulate the maximum possible n... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Simple Kadane Algorithms | simple-kadane-algorithms-by-dnanper-64hp | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | dnanper | NORMAL | 2025-01-28T07:09:33.903771+00:00 | 2025-01-28T07:09:33.903771+00:00 | 7 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Brute Force for all possible addition of the values -> bound [-49, 49] | brute-force-for-all-possible-addition-of-qitp | IntuitionSimply using the Kadane's Algorithms find the maximum sum of the subarray after the array modification.
Rest is in the code you can refer it i am feeli | Shivam_Kapoor | NORMAL | 2025-01-28T07:06:06.974654+00:00 | 2025-01-28T07:06:06.974654+00:00 | 6 | false | # Intuition
Simply using the Kadane's Algorithms find the maximum sum of the subarray after the array modification.
Rest is in the code you can refer it i am feeling a little sleepy
# Complexity
- Time complexity:
O(98 * N) ~ O(N)
- Space complexity:
O(98 * N) ~ O(N)
# Code
```cpp []
#define ll long long
class Solut... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Max Subarray Sum || Kadane's Algorithm | max-subarray-sum-kadanes-algorithm-by-ar-dgrn | IntuitionThe important observation to make is that nums can be divided into two parts: one part containing values i that can be incremented to k, and one part t | arthurcorrell | NORMAL | 2025-01-27T21:18:34.375129+00:00 | 2025-01-27T21:18:34.375129+00:00 | 19 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
The important observation to make is that $nums$ can be divided into two parts: one part containing values $i$ that can be incremented to $k$, and one part that contains $k$. For a certain number $i$ and a certain subdivision of the array i... | 0 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Original approach without using Kadane CPP solution | original-approach-without-using-kadane-c-pct6 | IntuitionApproachFor every target value in the array we can greedily find the maximum freq of k restricting subarray selection upto index i and utilizing postfi | Susm | NORMAL | 2025-01-27T20:07:26.687730+00:00 | 2025-01-28T07:00:15.022530+00:00 | 9 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
For every target value in the array we can greedily find the maximum freq of k restricting subarray selection upto index i and utilizing postfixsum of remaining k's on its right.
# Complexity
- Time complexity: O(N*M)
- Spac... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Short and elegant solution||Self-commented code | short-and-elegant-solutionself-commented-ydo8 | Code | andrjob | NORMAL | 2025-01-27T16:45:55.953433+00:00 | 2025-01-27T16:45:55.953433+00:00 | 8 | false |
# Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
array<int, 51> freq = {};
int result = 0;
int count = 0;
for (int num : nums) {
freq[num] = max(freq[num], count) + 1;
if (num == k) {
++result;
... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | JAVA| | java-by-tanishak07-n1o8 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | tanishak07 | NORMAL | 2025-01-27T16:20:44.881300+00:00 | 2025-01-27T16:20:44.881300+00:00 | 10 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ --> O(n)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->O(1)
... | 0 | 0 | ['Prefix Sum', 'Java'] | 0 |
maximum-frequency-after-subarray-operation | Kadans alogo | kadans-alogo-by-madhavendrasinh44-2568 | IntuitionLets use kadens algorithmApproachFirst find the frequency of all the element and then check for all the element in the map that who is most occuring in | Madhavendrasinh44 | NORMAL | 2025-01-27T16:08:25.581378+00:00 | 2025-01-27T16:08:25.581378+00:00 | 25 | false | # Intuition
Lets use kadens algorithm
# Approach
First find the frequency of all the element and then check for all the element in the map that who is most occuring in all the subarray.
# Complexity
- Time complexity: $$O(n)$$
- Space complexity: $$O(n)$$
# Code
```cpp []
class Solution {
public:
int check(vect... | 0 | 0 | ['Hash Table', 'Prefix Sum', 'C++'] | 0 |
maximum-frequency-after-subarray-operation | [CODE ONLY][DEBUG OUTPUT] PYTHON USING Lee's SOLUTION | code-onlydebug-output-python-using-lees-cfb17 | USING lee's solutionLINK: https://leetcode.com/problems/maximum-frequency-after-subarray-operation/solutions/6329937/java-c-python-kadaneDEBUG OUTPUTCode | greg_savage | NORMAL | 2025-01-27T15:39:11.083037+00:00 | 2025-01-27T15:39:11.083037+00:00 | 9 | false | # USING lee's solution
# LINK: https://leetcode.com/problems/maximum-frequency-after-subarray-operation/solutions/6329937/java-c-python-kadane
# DEBUG OUTPUT
```
DEBUG OUTPUT
Input
nums =
[1,2,3,4,5,6]
k =
1
Stdout
keys_to_freq are...
keys: 1, frequency: 1
keys: 2, frequency: 1
keys: 3, frequency: 1
keys: 4, frequency... | 0 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | [JavaScript] Easy & Fast DP Solution | javascript-easy-fast-dp-solution-by-liew-bzu7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | liew-li | NORMAL | 2025-01-27T12:28:31.090325+00:00 | 2025-01-27T12:28:31.090325+00:00 | 16 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['JavaScript'] | 0 |
maximum-frequency-after-subarray-operation | Java solution using recursion | java-solution-using-recursion-by-karthi_-bg1w | ApproachCount Occurrences: Use a recursive method to count the total occurrences of k in the array.Recursive Frequency Calculation: Use a recursive function to | KARTHI_SARAVANAN_T | NORMAL | 2025-01-27T10:29:59.561485+00:00 | 2025-01-27T10:29:59.561485+00:00 | 12 | false |
# Approach
**Count Occurrences:** Use a recursive method to count the total occurrences of k in the array.
**Recursive Frequency Calculation:** Use a recursive function to iterate through the array, updating frequency counts and keeping track of the maximum frequency achievable by changing elements to k.
# Complexi... | 0 | 0 | ['Java'] | 0 |
maximum-frequency-after-subarray-operation | Simple Greedy | simple-greedy-by-eskandar1-qtr6 | Complexity
Time complexity:
O(n)
Space complexity:
O(1)Code | Eskandar1 | NORMAL | 2025-01-26T21:55:18.153561+00:00 | 2025-01-26T21:55:51.475735+00:00 | 60 | false |
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n)
--
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(1)
---
# Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
int countK = count(nums.begin(), nums.end(... | 0 | 0 | ['Array', 'Math', 'Dynamic Programming', 'Greedy', 'C++', 'Java'] | 0 |
maximum-frequency-after-subarray-operation | Dynamic Programming Recursive Memoization | dynamic-programming-recursive-memoizatio-8rc4 | IntuitionAs the constraints on k is small i thought of using dpApproachRecursive Function (recur):The function explores the possibility of transforming elements | esh_war12 | NORMAL | 2025-01-26T21:29:32.968808+00:00 | 2025-01-26T21:29:32.968808+00:00 | 57 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
As the constraints on k is small i thought of using dp
# Approach
<!-- Describe your approach to solving the problem. -->
Recursive Function (recur):
The function explores the possibility of transforming elements in nums to equal k by add... | 0 | 0 | ['Dynamic Programming', 'C++'] | 0 |
maximum-frequency-after-subarray-operation | Simple Kidane's algorithm solution | O(n*50) time and O(1) space | simple-kidanes-algorithm-solution-on50-t-bw02 | IntuitionApproachComplexity
Time complexity: O(n∗50)
Space complexity: O(1)
Code | sachin_kashi | NORMAL | 2025-01-26T18:49:06.426382+00:00 | 2025-01-26T18:49:06.426382+00:00 | 16 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity: $$O(n*50)$$
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: $$O(1)$$
<!-- Add your space complexity here, e.g. $... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Finally done !! Never thought about kadane this way. | finally-done-never-thought-about-kadane-vekka | After grinding hard and going through several submissions, I got this. Feel free to share your views on my approach.Code | D_Neeraj_Dattu | NORMAL | 2025-01-26T18:11:13.820314+00:00 | 2025-01-26T18:11:13.820314+00:00 | 21 | false | After grinding hard and going through several submissions, I got this. Feel free to share your views on my approach.
# Code
```cpp []
class Solution {
public:
int solve(vector<int> &v1, vector<int> &v2) {
int n = v1.size() + v2.size();
vector<int> v(n, -1);
int i = 0, j = 0, k = 0;
... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | [Javascript] Kadane`s Algorithm O(50 * n) / O(1) | javascript-kadanes-algorithm-o50-n-o1-by-mm85 | Code | _savely | NORMAL | 2025-01-26T16:32:51.075771+00:00 | 2025-01-26T16:32:51.075771+00:00 | 22 | false |
# Code
```javascript []
/**
* @param {number[]} nums
* @param {number} k
* @return {number}
*/
var maxFrequency = function(nums, k) {
const kadane = (n, m) => {
let count = 0, max = 0;
for(const num of nums) {
count += num === n ? 1 : 0;
max = Math.max(max, count... | 0 | 0 | ['Array', 'Dynamic Programming', 'Greedy', 'Prefix Sum', 'JavaScript'] | 0 |
maximum-frequency-after-subarray-operation | SImple solution using prefix sum | simple-solution-using-prefix-sum-by-risa-mfqa | null | risabhuchiha | NORMAL | 2025-01-26T15:29:38.258911+00:00 | 2025-01-26T15:29:38.258911+00:00 | 29 | false |
```java []
class Solution {
public int maxFrequency(int[] nums, int k) {
HashSet<Integer>hs=new HashSet<>();
int c=0;
int ans=0;
for(int i:nums){
hs.add(i);
if(i==k)c++;
}
ans=0;
for(int j=1;j<=50;j++){
int s=0;
... | 0 | 0 | ['Java'] | 0 |
maximum-frequency-after-subarray-operation | Optimized Kadane | optimized-kadane-by-devbabbar7-xwcw | IntuitionWe don't need to iterate over all 50 values we can just iterate over the values present in the nums array. I could decrease the runtime for 5800 ms (fa | devbabbar7 | NORMAL | 2025-01-26T14:31:30.224434+00:00 | 2025-01-26T14:31:30.224434+00:00 | 21 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
We don't need to iterate over all 50 values we can just iterate over the values present in the nums array. I could decrease the runtime for 5800 ms (faster than 100%) to 2800 ms.
# Approach
<!-- Describe your approach to solving the problem... | 0 | 0 | ['Python3'] | 0 |
maximum-frequency-after-subarray-operation | Kadane Based Solution | kadane-based-solution-by-_leviathan-6630 | Code | _Leviathan_ | NORMAL | 2025-01-26T14:30:01.346642+00:00 | 2025-01-26T14:30:01.346642+00:00 | 17 | false |
# Code
```cpp []
class Solution {
public:
int search(int curr,vector<int>& nums,int k){
int tot=0;
int j=0;
int ans=0;
for(int i=0;i<nums.size();i++){
if(nums[i]==curr){
tot++;
}else if(nums[i]==k){
tot--;
}
... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | My Solutions | my-solutions-by-hope_ma-0398 | 1. Use the Kadane Algorithm2. Use the DP3. Use the same idea as 2 with the more efficient time complexity | hope_ma | NORMAL | 2025-01-26T14:02:31.564174+00:00 | 2025-01-26T14:02:31.564174+00:00 | 11 | false | **1. Use the `Kadane` Algorithm**
```
/**
* Time Complexity: O(n * num_range)
* Space Complexity: O(num_range)
* where `n` is the length of the vector `nums`
* `num_range` is (`max_num` - `min_num` + 1)
* `max_num` is the maximum number of the vector `nums`
* `min_num` is the minimum number of t... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | C++ solution using Kadane’s Algorithm. | c-solution-using-kadanes-algorithm-by-as-ac5v | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | ashishlc | NORMAL | 2025-01-26T13:30:09.557065+00:00 | 2025-01-26T13:30:09.557065+00:00 | 17 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | C++ MEMOIZED SOLUTION | c-memoized-solution-by-sj4u-z0x7 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | SJ4u | NORMAL | 2025-01-26T11:34:46.049759+00:00 | 2025-01-26T11:34:46.049759+00:00 | 24 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | O(n) Solution, like the Tetris Game | on-solution-like-the-tetris-game-by-lilo-gmvw | Intuition12 Years ago, I came accross an algorithm problem, whose solution was to use the Tetris thinking. This problem is the same.Approach
Count the number of | lilongxue | NORMAL | 2025-01-26T10:54:47.330716+00:00 | 2025-01-26T14:00:28.725290+00:00 | 21 | false | # Intuition
12 Years ago, I came accross an algorithm problem, whose solution was to use the Tetris thinking. This problem is the same.
# Approach
1. Count the number of ks in nums. It's the initial value of the result.
2. Go thru nums, and for each index, we know how many ks have been encountered (countFL), and how ma... | 0 | 0 | ['JavaScript'] | 0 |
maximum-frequency-after-subarray-operation | For me it was hard to find . | for-me-it-was-hard-to-find-by-madhavendr-v7wc | IntuitionHere we are checking for all 50 constrain.ApproachNow first make loop for 50 constrain and find the max frequency present in the array and then count p | Madhavendrasinh44 | NORMAL | 2025-01-26T10:27:00.106101+00:00 | 2025-01-26T10:27:00.106101+00:00 | 30 | false | # Intuition
Here we are checking for all 50 constrain.
# Approach
Now first make loop for 50 constrain and find the max frequency present in the array and then count plus the frequency found.
# Complexity
- Time complexity: $$O(50+nums.size())$$
- Space complexity: $$O(50 + n)$$
# Code
```cpp []
class Solution {
publ... | 0 | 0 | ['C++'] | 1 |
maximum-frequency-after-subarray-operation | For me it was hard to find . | for-me-it-was-hard-to-find-by-madhavendr-fc83 | IntuitionHere we are checking for all 50 constrain.ApproachNow first make loop for 50 constrain and find the max frequency present in the array and then count p | Madhavendrasinh44 | NORMAL | 2025-01-26T10:26:56.684270+00:00 | 2025-01-26T10:26:56.684270+00:00 | 11 | false | # Intuition
Here we are checking for all 50 constrain.
# Approach
Now first make loop for 50 constrain and find the max frequency present in the array and then count plus the frequency found.
# Complexity
- Time complexity: $$O(50+nums.size())$$
- Space complexity: $$O(50 + n)$$
# Code
```cpp []
class Solution {
publ... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | easy solution in O(n) just store diff and find max subarray sum | easy-solution-in-on-just-store-diff-and-sbncf | Intuitionsince the range of nums[i] is very less the diff between the nums[i] and k can be as large as -50 to 50 only so we can just check for each possible val | Unos555 | NORMAL | 2025-01-26T09:56:26.543936+00:00 | 2025-01-26T09:56:26.543936+00:00 | 18 | false | # Intuition
since the range of nums[i] is very less the diff between the nums[i] and k can be as large as -50 to 50 only so we can just check for each possible value and find the one with max freq
# Approach
-> store the diff of all elements from k which will be req number to add to make curr nums[i] to k
-> now for ea... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Normal Solution | normal-solution-by-maheshsyamk-g564 | IntuitionApproachComplexity
Time complexity:
Space complexity:
Code | MaheshSyamK | NORMAL | 2025-01-26T09:46:47.540149+00:00 | 2025-01-26T09:46:47.540149+00:00 | 17 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
# Approach
<!-- Describe your approach to solving the problem. -->
# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
`... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | C++ Solution :- Kadane Algorithm | c-solution-kadane-algorithm-by-shogun_th-z2cx | Approach
First, compute the initial count of elements equal to k in the array. This serves as the baseline count before any operations.
Identify all possible | Shogun_the_Great | NORMAL | 2025-01-26T09:21:15.581202+00:00 | 2025-01-26T09:21:15.581202+00:00 | 15 | false | # Approach
<!-- Describe your approach to solving the problem. -->
- First, compute the initial count of elements equal to k in the array. This serves as the baseline count before any operations.
- Identify all possible values of x that can be added to a subarray to convert some elements to k.
- These values are derive... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Array | C++ | O(N) | array-c-on-by-a_ck-l3ma | IntuitionThe problem revolves around identifying the maximum frequency of a number in the array while applying certain modifications. My initial thought was to | a_ck | NORMAL | 2025-01-26T09:17:22.008523+00:00 | 2025-01-26T09:17:22.008523+00:00 | 18 | false | # Intuition
The problem revolves around identifying the maximum frequency of a number in the array while applying certain modifications. My initial thought was to leverage a frequency array approach to keep track of counts efficiently. By iterating through the array and managing counts dynamically, the solution could b... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Prefix sum | Simple solution with 100% beaten | prefix-sum-simple-solution-with-100-beat-nvzf | IntuitionThe goal of the problem is to find the maximum frequency of a given integer k in the array nums after performing a single operation. In this operation, | Takaaki_Morofushi | NORMAL | 2025-01-26T09:07:58.574740+00:00 | 2025-01-26T09:07:58.574740+00:00 | 14 | false | # Intuition
The goal of the problem is to find the maximum frequency of a given integer `k` in the array `nums` after performing a single operation. In this operation, we can select a subarray and add an integer `x` to all the elements in that subarray. The challenge is to maximize the frequency of `k` through this ope... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | Kadane Go Solution !!! | kadane-go-solution-by-dipak__patil-0drb | Code | dipak__patil | NORMAL | 2025-01-26T08:52:10.269059+00:00 | 2025-01-26T08:52:10.269059+00:00 | 10 | false | # Code
```golang []
func maxFrequency(nums []int, k int) (res int) {
var (
countMap = map[int]int{}
n int
)
for _, n = range nums {
countMap[n]++
}
kadane := func(num int) int {
var currRes, currCount int
for _, n = range nums {
if n == k {
currCount--
}
if n == num {
currCount++... | 0 | 0 | ['Go'] | 0 |
maximum-frequency-after-subarray-operation | check each x, maximum subarray sum | check-each-x-by-user5285zn-h3cd | We fix x and find the interval in which we convert all x to k. b contains the difference between the frequencies between x and k in the prefix. | user5285Zn | NORMAL | 2025-01-26T08:40:25.356857+00:00 | 2025-01-26T08:43:53.834945+00:00 | 7 | false | We fix $x$ and find the interval in which we convert all $x$ to $k$. $b$ contains the difference between the frequencies between $x$ and $k$ in the prefix.
```rust []
fn f(x:i32, nums: &[i32], k: i32) -> i32 {
let mut a = 0;
let mut b = 0;
let mut best = 0;
for &y in nums.iter() {
if y == x {b ... | 0 | 0 | ['Rust'] | 0 |
maximum-frequency-after-subarray-operation | Subtract all possibilities: O(n*50) | subtract-all-possibilities-on50-by-tejes-c33d | Complexity
Time complexity: O(n)
Space complexity: O(n)
Code | tejesh_avadanam | NORMAL | 2025-01-26T08:21:13.508089+00:00 | 2025-01-26T08:21:13.508089+00:00 | 15 | false | # Complexity
- Time complexity: O(n)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
- Space complexity: O(n)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
# Code
```cpp []
class Solution {
public:
int maxFrequency(vector<int>& nums, int k) {
int n = nums.size();
int maxFrequency = ... | 0 | 0 | ['C++'] | 0 |
maximum-frequency-after-subarray-operation | C++ solution using prefix sum and map with intuition and approach | c-solution-using-prefix-sum-and-map-with-zr2j | Intuitionfor each index if we considering subarry ending index as curr index we need to find a index from 0 to i for which our ans will be max.for this we can c | jatinaggarwal2812 | NORMAL | 2025-01-26T07:49:57.934144+00:00 | 2025-01-26T07:49:57.934144+00:00 | 61 | false | # Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
for each index if we considering subarry ending index as curr index we need to find a index from 0 to i for which our ans will be max.
for this we can convert every nums[i] to k from 0 to i, so we can convert from last index where nums[i]... | 0 | 0 | ['Prefix Sum', 'C++'] | 0 |
minimum-edge-weight-equilibrium-queries-in-a-tree | 【C++ | Java | Python】Prefix-sum and LCA on the tree, explained in detail | c-java-python-prefix-sum-and-lca-on-the-7nlor | I know almost nothing about English, pointing out the mistakes in my article would be much appreciated.\n\n> In addition, I\'m too weak, please be critical of m | RealFan | NORMAL | 2023-09-03T07:57:47.144620+00:00 | 2023-09-14T08:52:47.923771+00:00 | 3,602 | false | > **I know almost nothing about English, pointing out the mistakes in my article would be much appreciated.**\n\n> **In addition, I\'m too weak, please be critical of my ideas.**\n---\n\n[toc]\n\n# Intuition\n1. For this kind of problem involves the "path between two nodes on the tree", **the first intuition is to cons... | 81 | 1 | ['Depth-First Search', 'C++', 'Java', 'Python3'] | 13 |
minimum-edge-weight-equilibrium-queries-in-a-tree | LCA in C++, java and python | lca-in-c-java-and-python-by-cpcs-0ira | Intuition\nUse LCA.\n\n# Approach\nThere are at most 26 different edge weights. For each node, we can count the number of edges of each weight from root to the | cpcs | NORMAL | 2023-09-03T04:00:48.967731+00:00 | 2023-09-03T12:12:03.664377+00:00 | 2,198 | false | # Intuition\nUse LCA.\n\n# Approach\nThere are at most 26 different edge weights. For each node, we can count the number of edges of each weight from root to the current node.\nAnd then for each query (x, y),\nThe number of edges of a particular weight = num[x] + num[y] - 2 * num[LCA(x, y)].\nThen we just calculate the... | 20 | 1 | ['Python', 'C++', 'Java', 'Python3'] | 6 |
minimum-edge-weight-equilibrium-queries-in-a-tree | Video Explanation (Optimizing starting from Brute force) | video-explanation-optimizing-starting-fr-b86d | Explanation\n\nClick here for the video\n\n# Code\n\n#define pii pair<int, int>\n#define F first\n#define S second\n\nconst int N = 1e4+1;\nconst int W = 27;\n\ | codingmohan | NORMAL | 2023-09-03T06:36:42.765442+00:00 | 2023-09-03T06:36:42.765493+00:00 | 539 | false | # Explanation\n\n[Click here for the video](https://youtu.be/MJRMqbSJW24)\n\n# Code\n```\n#define pii pair<int, int>\n#define F first\n#define S second\n\nconst int N = 1e4+1;\nconst int W = 27;\n\nvector<vector<int>> par(15, vector<int>(N, 0));\nvector<vector<int>> frq(N, vector<int>(W, 0));\nvector<int> lvl(N, 0);\n... | 16 | 0 | ['C++'] | 0 |
minimum-edge-weight-equilibrium-queries-in-a-tree | [Python3] binary lifting | python3-binary-lifting-by-ye15-easa | For solutions of weekly 361, please pull this commit. \n\n\nclass Solution:\n def minOperationsQueries(self, n: int, edges: List[List[int]], queries: List[Li | ye15 | NORMAL | 2023-09-03T04:01:17.188074+00:00 | 2023-09-06T01:13:41.047459+00:00 | 791 | false | For solutions of weekly 361, please pull this [commit](https://github.com/gaosanyong/leetcode/commit/c21e07fdae41e9dcb60c3845e718c256302215fc). \n\n```\nclass Solution:\n def minOperationsQueries(self, n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:\n tree = [[] for _ in range(n)]\n ... | 15 | 0 | ['Python3'] | 2 |
minimum-edge-weight-equilibrium-queries-in-a-tree | Euler Tour | euler-tour-by-votrubac-tlnm | This problem is a great brush-up on LCA.\n\nWe can use Tarjan\'s (since we know all queries in advance) or Binary Lifting, but for me, the Euler tour was the mo | votrubac | NORMAL | 2023-09-03T23:03:35.171460+00:00 | 2023-09-03T23:17:00.491534+00:00 | 767 | false | This problem is a great brush-up on LCA.\n\nWe can use Tarjan\'s (since we know all queries in advance) or Binary Lifting, but for me, the Euler tour was the most intuitive approach.\n\nThe important constraint is that the weight is limited to 26. So, we can store the number of edges of each weight from a root (we can ... | 12 | 0 | ['C'] | 2 |
minimum-edge-weight-equilibrium-queries-in-a-tree | Bitmask + graph solution [EXPLAINED] | bitmask-graph-solution-explained-by-r9n-4y15 | IntuitionFind the least number of operations to make all paths between queried nodes use the same weight. To do this, we need to calculate the most frequent wei | r9n | NORMAL | 2025-01-15T21:51:43.244936+00:00 | 2025-01-15T21:51:43.244936+00:00 | 32 | false | # Intuition
Find the least number of operations to make all paths between queried nodes use the same weight. To do this, we need to calculate the most frequent weight in each path and subtract it from the total edges between the nodes.
# Approach
I use a graph, queries, and Tarjan's algorithm with disjoint sets to com... | 11 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'Depth-First Search', 'Breadth-First Search', 'Graph', 'Topological Sort', 'Memoization', 'Bitmask', 'Strongly Connected Component', 'Python3'] | 0 |
minimum-edge-weight-equilibrium-queries-in-a-tree | ✅ C++ | Binary Lifting🔥🔥 | LCA | 🚀🚀 Simple🔥 Clean Code | Easy to Understand✅✅ | c-binary-lifting-lca-simple-clean-code-e-2q47 | Code\n\nclass Solution {\npublic:\n vector<int> depth;\n int weights[10004][27];\n int par[10004][16];\n vector<vector<pair<int, int>>> g;\n void | pkacb | NORMAL | 2023-09-03T14:52:02.435827+00:00 | 2023-09-03T14:56:02.285997+00:00 | 454 | false | # Code\n```\nclass Solution {\npublic:\n vector<int> depth;\n int weights[10004][27];\n int par[10004][16];\n vector<vector<pair<int, int>>> g;\n void dfs(int src, int paren = -1)\n {\n for(auto [child, wt] : g[src])\n {\n if(child == paren)\n continue;\n\n ... | 7 | 0 | ['Bit Manipulation', 'Depth-First Search', 'Graph', 'C++'] | 0 |
minimum-edge-weight-equilibrium-queries-in-a-tree | Binary lifting for LCA in C++ with Explanation | binary-lifting-for-lca-in-c-with-explana-6s4f | Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nWe will store count of | RamKumarGoyal | NORMAL | 2023-09-04T08:19:09.458285+00:00 | 2023-09-04T08:22:16.648798+00:00 | 364 | false | # Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe will store count of each type of edge from root node to any node.\nAlso create 2D DP for doing binary lifting.\nFor each query we will find their LCA and then we al... | 6 | 0 | ['Dynamic Programming', 'Bit Manipulation', 'Tree', 'C++'] | 2 |
minimum-edge-weight-equilibrium-queries-in-a-tree | LCA | c++ | lca-c-by-betoscl-vryr | Approach \n\nSet the weight by which all edges are to be changed, note that the weight can be at most $w\leq 26$ so we can iterate over all possible weights. \n | BetoSCL | NORMAL | 2023-09-03T04:01:33.190927+00:00 | 2023-09-03T21:02:01.237514+00:00 | 876 | false | # Approach \n\nSet the weight by which all edges are to be changed, note that the weight can be at most $w\\leq 26$ so we can iterate over all possible weights. \n\nNow knowing how many edges with weight $w$ there are in a path is a task similar to obtaining the distance for any pair in a tree, for this we will build a... | 6 | 0 | ['C++'] | 1 |
minimum-edge-weight-equilibrium-queries-in-a-tree | C++ solution || LCA by Binary Lifting | c-solution-lca-by-binary-lifting-by-avad-ueh9 | \n# Code\n\nclass Solution {\npublic:\n int m;\n void dfs(int i,int par,int level,vector<vector<int>>&table,vector<vector<pair<int,int>>>&adj,vector<vecto | avadhut7969 | NORMAL | 2023-09-03T12:56:38.651487+00:00 | 2023-09-03T12:56:38.651506+00:00 | 59 | false | \n# Code\n```\nclass Solution {\npublic:\n int m;\n void dfs(int i,int par,int level,vector<vector<int>>&table,vector<vector<pair<int,int>>>&adj,vector<vector<int>>&w,vector<int>&d){\n d[i]=level;\n table[0][i]=par;\n for(auto it:adj[i]){\n if(it.first==par) continue;\n ... | 4 | 0 | ['Tree', 'Depth-First Search', 'C++'] | 0 |
minimum-edge-weight-equilibrium-queries-in-a-tree | Lowest Common Ancestor | lowest-common-ancestor-by-jeffreyhu8-w1qr | Intuition\nA brute force solution is to find the path from a to b for each query a, b, then find the most common element. This is $O(n\cdot\mathrm{queries.lengt | jeffreyhu8 | NORMAL | 2023-09-03T04:02:10.607570+00:00 | 2023-09-03T04:02:10.607592+00:00 | 600 | false | # Intuition\nA brute force solution is to find the path from `a` to `b` for each query `a, b`, then find the most common element. This is $O(n\\cdot\\mathrm{queries.length})$, which is too slow.\n\n# Approach\nProblems involving paths on trees can sometimes be solved using lowest common ancestor (LCA). For instance, th... | 4 | 0 | ['Python3'] | 1 |
minimum-edge-weight-equilibrium-queries-in-a-tree | Video Solution | Complete Contest | Explanation With Drawings | In Depth | video-solution-complete-contest-explanat-q442 | Intuition, approach, and time complexity dicussed in detail in video solution\nhttps://youtu.be/j3sz5xdYRYg\n\n# Code\nJava\n\nclass Solution {\n List<List<i | Fly_ing__Rhi_no | NORMAL | 2023-09-03T17:24:25.448056+00:00 | 2023-09-03T17:24:25.448079+00:00 | 321 | false | # Intuition, approach, and time complexity dicussed in detail in video solution\nhttps://youtu.be/j3sz5xdYRYg\n\n# Code\nJava\n```\nclass Solution {\n List<List<int[]>> graph;\n int[] parentOf;\n int[] depthLevel;\n int[][] wtFreq;\n int[][] parentOfMatrix;\n public int[] minOperationsQueries(int n, i... | 3 | 0 | ['Java'] | 0 |
minimum-edge-weight-equilibrium-queries-in-a-tree | LCA using Binary Lifting || C++ || DP (Memoization) | lca-using-binary-lifting-c-dp-memoizatio-phzm | \n\n# Code\n\nclass Solution {\npublic:\n int count[10001][27];\n \n void dfs(int u, int p, int **memo, vector<int> &lev, int log, vector<pair<int,int> | 071_Prashant | NORMAL | 2023-09-03T05:10:58.206342+00:00 | 2023-09-03T05:14:26.967746+00:00 | 492 | false | \n\n# Code\n```\nclass Solution {\npublic:\n int count[10001][27];\n \n void dfs(int u, int p, int **memo, vector<int> &lev, int log, vector<pair<int,int>> adj[])\n{\n memo[u][0] = p;\n for (int i = 1; i <= log; i++)\n memo[u][i] = memo[memo[u][i - 1]][i - 1];\n for (auto x : adj[u])\n {\n ... | 3 | 0 | ['Dynamic Programming', 'C++'] | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.