PRANAY's 1st September 2025


After a long and exhausting time at the college and at my club Innogeeks where I am now a coordinator, I decided to solve some question on leetcode and study some tropics which would improve my logical thinking and ability to solve questions
Maximum Average Pass Ratio
First I solved this question which was the question of the day initially I had the intuition of maximising the lowest ratio but later I realised by doing so I was not maximising the average ratio but the median of the average ratio so I switched to maximising the numerator by finding out to which class shall I add the the excellent extra student so that it may result in maximum gain and hence increase the numerator hence increasing the average ratio.
Integer Break
Next I solved this question where I need to break a given number into such numbers which on addition gives the given number and maximum product so here the idea was not intuitive for me but after taking some hints I realised the magic of 3 which told me that 3 will always give you maximum product for these type of questions and the edge case was of remainder if the remainder is 1 we will be in loss so remove one 3 and replace it by two 2’s which will increase the product
Most Frequent Subtree Sum
When I saw this question at first glance I thought it was easy and yes it was easy for me after solving over 50+ questions of Trees the only thing I tried to optimise here was to do the count of max frequency and storing the sum with maximum frequency as well as finding the maximum frequency ,all these in one loop.
The kth Factor of n
This question can be easily solved by the iterating approach which has a time complexity of O(n) but the follow up ask for a time complexity better then O(n) for which I used the concept of pair factor which tells is that if i is a factor of n then n/i is also a factor of n so I knew now I knew that have to traverse only till root n as it will cover all the factors but now come the part to find the kth for which I may need to sort the list of all the factors but to avoid the S log S sorting where S is the number of factors I chose to use a List with LinkedList implementation such that the order is maintained and I myself got appreciated by the way I used.Here is the line of code :-
for(int i=(int)Math.sqrt(n);i>0;i--)
{
//Now we will add factors to the list such that the smaller value is added to front and greater value is added to the back
if(n%i==0)
{ls.addFirst(i);
if(i!=n/i)
//checking for the same element
ls.addLast(n/i);}
}
Also beside solving this I also learnt how to add a new element to a heap in log(n) time complexity and how to delete a element from a Heap in O(log n) time complexity as well
Subscribe to my newsletter
Read articles from PRANAY JAISWAL directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
