Counting Bits In a Number – Leetcode

Given an integer n, return an array ans of length n + 1 such that for each i (0 <= i <= n), ans[i] is the number of 1‘s in the binary representation of i. Example 1: Input: n = 2 Output: [0,1,1] Explanation: 0 –> 0 1 –> 1 2 –> 10 Example 2: Input: n = 5 Output: [0,1,1,2,1,2] Explanation: 0 –> 0 1 –> 1 2…

Read more...

Time Needed to Inform All Employees – Leetcode [TREE, DFS]

A company has n employees with a unique ID for each employee from 0 to n – 1. The head of the company is the one with headID. Each employee has one direct manager given in the manager array where manager[i] is the direct manager of the i-th employee, manager[headID] = -1. Also, it is guaranteed that the subordination relationships have a tree structure. The head of the…

Read more...

Print Digit of Number In Words

Given a number N, Print digits of that number in words. eg, 100 should be written as One Zero Zero Solution [Using Recursion]

Read more...

Palindromic Partitioning

Problem Statement Partitioning the array is said to be a palindrome partitioning if every subarray of the partition is a palindrome. For example, 1 | 2 2 2 | 23 | 4 is a palindrome partitioning of array { 1,2,2,2,23,4 }. Given an integer array, you have to find out the fewest cuts needed for palindrome partitioning. For example,…

Read more...

String to Integer (atoi)

Implement atoi which converts a string to an integer. The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain…

Read more...

HashMap in JAVA

Consider a scenario where we need to store data in the form of key value pairs. Which data structure will we use? Well, The obvious answer which comes in our mind is Map. HashMap is Hash table based implementation of the Map interface which stores data in the form of key value pairs. This class provides…

Read more...

Convert int to String and String to int

This is one of the most occurred scenario where we need to convert a Integer to String or a String to Integer. We can attain that by using methods of wrapper classes. Here we are discussing about Integer -> String or String ->Integer. String to int To convert String to Integer we can use parseInt()….

Read more...