Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your code should return the index of the first number and ...
Given a sorted array and a number x, write a function that counts the occurrences of x in the sorted array
Given a sorted array and a number x, write a function that counts the occurrences of x in the array. Expected time complexity: O(Logn)
For example:
In...
Length of the Longest Consecutive 1s in Binary Representation
Given a number n, find length of the longest consecutive 1s in its binary representation.
For Example:
Input: n = 100
Output: 2
Explanation: Binary...
Check if a Singly Linked List is Palindrome or not
Problem: Given a singly linked list, determine if its a palindrome. Return 1 or 0 denoting if its a palindrome or not, respectively. Can you do it in...
Find The First Non Repeated Character In A String
Problem: Given a string, find the first non-repeating character in it.
For example:
Input s = "stress"
Output: t
Input: s = "InterviewDesk"
Output...
Number of buildings facing the Sun
Problem: The heights of the building is given in an array. Buildings are facing the sun. You have to tell which all buildings will see the sunset. It...
Check if a linked list is Circular Linked List
Problem: Given a singly linked list, find if the linked list is circular or not.
Circular Linked List: A linked list is called circular if it no...
Reverse every K nodes of a Linked List
Problem: Given a linked list and a positive number K, reverse every K nodes in the list.
For example:
Input L1: 1 -> 2 -> 3 -> 4 -> 5 ...
Merge two sorted arrays
Problem: Given two sorted arrays, the task is to merge them in a sorted manner.
For example:
Input : arr1[] = { 5, 8, 9}
arr2[] = {4, ...
Find Nth Fibbonacci Number
Problem: Find Nth fibonacci number in O(logN) time complexity.
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...
In mathematical ...
Minimum number of squares whose sum equals to given number N
Problem: Given number N, find the least number of perfect square number sum needed to get N.
For example:
Input: n = 20
Output: 2
20 = (16 + 4) i...
Find maximum of minimum for every window size in a given array
Problem: Given an integer array of size n, find the maximum of the minimum’s of every window size in the array.
For example:
Input: arr[] = {10, 2...
Spiral Order Traversal of Binary Tree
Problem: Given a binary tree, print its nodes level by level in spiral order.
For example:
The spiral order traversal of the tree above is (1, 3...
Count triplets with sum smaller than a given value
Problem: Given an array of distinct integers and a sum value. Find count of triplets with sum smaller than given sum value.
For example:
Input arr...
Find Nth Magic Number
Problem: Given a number n, find out the nth Magic Number.
Magic Numbers: A magic number is defined as a number which can be expressed as a power of...
Two numbers with sum closest to zero
Problem: Given an integer array, you need to find the two elements such that their sum is closest to zero.
For example:
Input: arr[] = {-21, -67...
Count all numbers with unique digits (in decimal) in the range [1, N]
Problem: Given a range, print all numbers having unique digits.
For example:
Input : 10 20
Output : 10 12 13 14 15 16 17 18 19 20
11 does not has...
Count number of occurrences in a sorted array
Problem: Given a sorted array and a number x, write a program that counts the occurrences of x in the given array. Can you do in less than O(n)?
Fo...
Generate a sum tree of given binary tree
Problem: Given a Binary Tree where each node has positive and negative values. Convert this to a tree where each node contains the sum of the left an...