Let's talk about LeetCode Biweekly Contest 114 and Weekly Contest 364.
Biweekly Contest 114
Question 1: We can just take the simple set, and check that if the length of the set becomes k, then return n-i.
Submission: https://lnkd.in/g472NF-S
Question 2: For this, I might overthink, but I first found out that if freq is 1 then return -1, else if we got odd then we can remove 3, for values like 10 and, 4 we can first remove 4, then freq/3.
Submission: https://lnkd.in/gaVmvFam
Question 3: It is kind of easy, just do cnt++ when you got And as totalAnd.
Submission: https://lnkd.in/gxwkqxQV
Question 4: For this, we can calculate the child's sums, and when we get a child's values as divisible by k, we can do cnt+=1, and return 0 from there.
Submission: https://lnkd.in/gGafVTW7
Weekly Contest 365
Question 1 - For this, We can use prefixMax and suffixMax, and then iterate through the loop and get the maximum result.
Submission Code - https://lnkd.in/gp6FGh9Q
Question 2 - It is the same as Question 1.
Submission Code - https://lnkd.in/gp6FGh9Q
Question 3 - It is somewhat of a sliding window question, we can get the target/sum as our ans, and then we will find the window of the sum as a target.
Submission Code - https://lnkd.in/g-cWu9My
Question 4 - We can use topo sort to get the nodes, that are not a part of the cycle, then we can simply use DFS to get the length of the nodes, that are part of a cycle, and then we can get the total path for the non-cyclic nodes.
Submission Code - https://lnkd.in/gRizTehc
Connect 🤝 : Prateek Goel
#leetcode #contest #globralRank #weekly #gfg #rank #linkedIn #learning #biweekly #ranks #coding
We love #fbae36 🙂