A LeetCode a day
Two Sum *

Given an array of integers, return indices of the two numbers such that they add up to a specific target

So, what they mean is that I am given an array of numbers and a target number. I need to add two numbers in the array to equal the target number. In return, I have to provide those two number’s indexes in an array.

Here is my solution in JS above. I used a double loops to deal with it? which end up getting a 1712ms runtime total(pretty slow). I guess the time complexity is O(n^2) which is generally considering to avoid.

Later on, I make an approach using python, and this time I’m choosing O(n) as my runtime. You can see the code above. The result I’m getting is 52ms which is way faster than the initial sub.


1431. Kids With the Greatest Number of Candies *

Given the array candies and the integer extraCandies, where candies[i] represents the number of candies that the ith kid has.

For each kid check if there is a way to distribute extraCandies among the kids such that he or she can have the greatest number of candies among them. Notice that multiple kids can have the greatest number of candies.

I need to find the least fortunate kid in the group who cannot get enough candies and bump up to be the greatest candy owner?

Here is my Js solution above which end up with a 72ms runtime. I used Sort() method to get the biggest number in that array. Then, I can use that number as reference to compare in the map callback function.

In the same way, I did a trial in Python, with the same logic that I applied in my JS solution. But the runtime is 32ms(two times less).


5. Longest Palindromic Substring **

Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.

TBH, I had been stuck in this problem for quite a long time. I ended up reading someone’s python solution and figured it out. I also implemented the python logic in javascript later on.