LEETCODE: MINIMIZE DEVIATION IN ARRAY

  1. Minimize Deviation in Array A couple of things to notice. Odd elements can only be changed once, which makes them even.

Read more

LEETCODE: IPO

  1. IPO Note that, at any point, if we know what is the most profitable project within our current budget, we can solve this problem.

Read more

LEETCODE: SINGLE ELEMENT IN A SORTED ARRAY

  1. Single Element in a Sorted Array There are simpler methods like finding xor of all elements. However, the time complexity would be O(N) in that case.

Read more

LEETCODE: MINIMUM FUEL COST TO REPORT TO THE CAPITAL

  1. Minimum Fuel Cost to Report to the Capital At each node, we just need to know how many people are passing through this node.

Read more

LEETCODE: SHORTEST PATH WITH ALTERNATING COLORS

  1. Shortest Path with Alternating Colors Pretty much usual BFS problem with another dimension, colors. We need to store a Pair of NodeId and Color in the queue instead of only nodes.

Read more

LEETCODE: AS FAR FROM LAND AS POSSIBLE

  1. As Far from Land as Possible This is a classic BFS problem. Put all the land cells in the queue and run Breadth First Search to find farthest water cell or vice versa.

Read more

LEETCODE: FRUIT INTO BASKETS

  1. Fruit Into Baskets Maintain a sliding window to keep track of indexes of at most two different types of fruits.

Read more

LEETCODE: SHUFFLE THE ARRAY SOLUTION IN KOTLIN

  1. Shuffle the Array Zip the two half lists, flatten. class Solution { fun shuffle(nums: IntArray, n: Int) = nums.zip( nums.

Read more

LEETCODE: FIND ALL ANAGRAMS IN A STRING SOLUTION IN KOTLIN

  1. Find All Anagrams in a String Very similar to this.

LEETCODE: PERMUTATION IN STRING SOLUTION IN KOTLIN

  1. Permutation in String To verify if a substring in S2 is a permutation of S1, counting the frequency of characters in that substring and comparing them with characters frequency of S1 should do it.

Read more