Reverse Integer Problem

Problem Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the signed 32-bit integer range [-2^31, 2^31 - 1], then return 0. Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Examples Example1: x = 123, return 321 Example2: x = -123, return -321 ...

Palindrome Number Problem

Problem Determine whether an integer is a palindrome. Follow up Do this without extra space. Definition Palindrome Definition Examples Example 1: Input: x = 121 Output: true Explanation: 121 reads as 121 from left to right and from right to left. Example 2: Input: x = -121 Output: false Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome. ...

Construct Binary Tree from Inorder and Postorder Traversal

Problem Given two integer arrays inorder and postorder where inorder is the inorder traversal of a binary tree and postorder is the postorder traversal of the same tree, construct and return the binary tree. Example Example 1: 3 / \ 9 20 / \ 15 7 ...

First Unique Character in a Stream of Characters

Find First Unique Character From a Stream of Characters Problem Given a string A denoting a stream of lowercase alphabets. You have to make new string B. B is formed such that we have to find first non-repeating character each time a character is inserted to the stream and append it at the end to B. If no non-repeating character is found then append ’#’ at the end of B. ...

Merge K Sorted Lists

Problem You are given an array of k linked-lists lists, each linked-list is sorted in ascending order. Merge all the linked-lists into one sorted linked-list and return it. Examples 1 -> 10 -> 20 4 -> 11 -> 13 3 -> 8 -> 9 will result in 1 -> 3 -> 4 -> 8 -> 9 -> 10 -> 11 -> 13 -> 20 ...

Rotate n x n matrix by 90 degrees

Problem You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). Another way to ask the same problem Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a method to rotate the image by 90 degrees. Can you do this in place? Examples Example 1: ...

Square root of an integer Problem

Problem Implement int sqrt(int x). OR Compute and return the square root of x. OR If x is not a perfect square, return floor(sqrt(x)) OR floor(√n) OR Given a non-negative integer x, compute and return the square root of x. Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned. ...

Vertical Order Traversal of a Binary Tree Problem

Vertical Order Traversal of a Binary Tree Problem Problem Given the root of a binary tree, calculate the vertical order traversal of the binary tree. For each node at position (row, col), its left and right children will be at positions (row + 1, col - 1) and (row + 1, col + 1) respectively. The root of the tree is at (0, 0). The vertical order traversal of a binary tree is a list of top-to-bottom orderings for each column index starting from the leftmost column and ending on the rightmost column. There may be multiple nodes in the same row and same column. In such a case, sort these nodes by their values. ...

Container With Most Water

Problem You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the ith line are (i, 0) and (i, height[i]). Find two lines that together with the x-axis form a container, such that the container contains the most water. Return the maximum amount of water a container can store. Notice that you may not slant the container. ...

Binary Tree Inorder Traversal

Problem Given a binary tree, write a non recursive or iterative algorithm for Inorder traversal. Inorder Traversal First, visit all the nodes in the left subtree Then the root node Visit all the nodes in the right subtree inorder(root->left) display(root->data) inorder(root->right) Example Example 1: 1 \ 2 / 3 ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy