Problem Statement This problem is from Leetcode – Number Complement. The problem statement is as below: The complement of an integer is the integer you get when you flip all the 0’s to 1’s and all the 1’s to 0’s in its binary representation. Given an integer num, return its complement. Solution This problem is […]
Assign Cookies – Leetcode #455
Problem Statement This problem is from Leetcode – Assign Cookies. The problem statement is as below: Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor g[i], which is the minimum size of a […]
Find All Numbers Disappeared in an Array – Leetcode #448
Problem Statement This problem is from Leetcode – Find All Numbers Disappeared in an Array. Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums. Example 1: Input: nums = [4,3,2,7,8,2,3,1] Output: […]
How many ways to express a natural number N as sum of two or more consecutive natural numbers
Problem Statement This problem is asking us to find out the number of ways a natural number N can be expressed as a sum of two or more consecutive natural numbers. For example: 5 can be expressed as 2+3. This gives us the count as 1. 9 can be expressed as 4+5 and 2+3+4. This […]
Longest Uniform Sub-String
Problem Statement Given a string, find the longest uniform sub-string in it. Return the repeating character and the number of times it repeats. Solution Let us take an example string like “abcdddss“. The question is asking us to return the longest sub-string with the same characters. In this case the longest uniform sub-string is “ddd”. […]
First Non-Repeating Character
Problem Statement Given an input string, find the first non-repeating character in it. Solution Let us take an example string like “aabccdeff“. The question is asking us to return the first character that does not repeat. In this case the first non-repeating character is “b“ Approach Declare a hashmap with Character as key and Boolean […]