Always make sure that we understand the problem statement first. There is an array of integers nums and we need to determine the number of good pairs. A pair (i , j ) is said to be good, if nums[i] == nums[j] and i < j. We need to determine how many pairs can we form that hold this condition. Let us look at some sample test cases: Input: nums = [ 1 , 2 , 3 , 1 , 1 , 3 ]Output: 4Explanation:There are 4 good pairs. (0 …
nikoo28
nikoo28
a techsavvy guy and a design buff... I was born with the love for exploring and want to do my best to give back to the community. I also love taking photos with my phone to capture moments in my life. It's my pleasure to have you here.


Given a sorted array and a target element, find its first and last index.

A camel case is a special string representation in which the first word starts with a small letter, and all other words start with an upper case character. Given such a string, find the total number of words

Let us try to understand this problem statement first. We have some strings that needs to be super reduced in size. The string consists of english alphabets from a to z, and they can be duplicated at some places. If we see two adjacent characters that are same, they can be eliminated. Following this pattern we have to return a super compressed/reduced string. Let us look at some sample test cases: Input: aabcccddOutput: “bc”Explanation:aabcccdd > bcccdd > bcdd > bc(we eliminate two same adjacent characters at each step) Input: abbaOutput: …

Let us try to understand this problem statement first. We are in charge of a fancy circus and 2 kangaroos have to jump on a number line. The interesting part is that both the kangaroos have a different start position, and different jump distances. It is a little tricky to understand, the problems asks to calculate the number line jumps such that both the kangaroos are at the same position. We will try to simplify this using some diagrams, and see how the kangaroos actually jump. In the given test …

Delete a node from a linked list at 3 places. Beginning, end and somewhere in the middle. It is all about updating the pointers.

Let us try to understand this problem statement first. It is actually very verbose. We will try to simplify it as much as possible. Christy wants to give chocolates to her colleagues, and at the same time tries to ensure that everyone has equal chocolates at the end. To achieve this she either gives 1,2, or 5 chocolates to everyone except any one individual. Everytime she does this, it is counted as 1 operation. We need to make sure that Christy can achieve this task in the minimum number of …

Question: Given a two strings, find the minimum number of characters that must be deleted to make them anagrams. Input: str1 = “a b c”, str2 = “a m n o p”Output: 6 Let us try to understand this problem statement and its test case first. We have two strings of english alphabet which may or may not have the same length. Anagrams are two words with same characters and frequencies. It is not necessary that the order of the characters is same. We have to determine, how many total …

Question: Given a string, count the number of times the letter ‘a’ is repeated. Input: str = “abcac”, n= 10 Output: 4 Let us try to understand this problem statement and its test case first. You have a string of lowercase English letters, that is repeated infinitely many times. Along with it, you also have a number ‘n’. You need to find out how many times the letter a appears in the first n characters of this infinite string. Let us look at a sample test case. Upon looking at …

A queue is a linear data structure working on First In First Out policy. But some use cases can require different solutions. We can create different queue types with the same basic idea. This post describes more about them