## Find The Minimum time difference

Minimum time difference Given a list of 24-hour clock time points in “HH:MM” format. Write a program to find the minimum minutes difference between any two time-points in the list. Example:  Given hours: [00:00, 03:00, 22:30] minimum time difference: 90 Given hours: [01:59, 03:00, 21:50, 22:30] minimum time difference: 40 Solution: Convert all the given … Read more

## Departure and Destination Cities in a given itinerary

You are on a business trip and traveling from one city to another. you have a stack of unsorted flight boarding passes. The only departure city and destination city are on the boarding pass. how do you find the first departure city and your final destination city, Example:  [Dallas, Austin], [Houston, Dallas], [Austin, Seattle] Output: … Read more

## Given an array, rank its elements

Given an array of numbers, write a program to rank the array elements. Example: Given array: [22, 11, 44, 66, 55] Rank: [2, 1, 3, 5, 4] Given array: [15, 12, 11, 10, 9] Rank: [5, 4, 3, 2, 1] Given array: [10, 20, 30, 40, 50] Rank: [1, 2, 3, 4, 5] Given array: … Read more

## Find Three Consecutive Odd Numbers in an array

GIven an array of numbers, find out if array contains three consecutive odd numbers Example: [2, 4, 1, 3, 4, 1, 3, 6] Three consecutive odds: false [2, 4, 1, 3, 4, 1, 3, 6] Three consecutive odds: true [2, 4, 1, 3, 4, 1, 3, 6] Three consecutive odds: true Solution: Initialize count = … Read more

## Maximum Depth of Valid Nested Parentheses in an arithmetic expression

Given an arithmetic expression which operators, operands and brackets. You need to find out the maximum depth of valid nested parentheses. If parentheses are not valid ( means not well formed ) then return -1.  Example: Solution: Input: 1 + (2*((3+4)/(2-1)))/2+56 Maximum Depth: 3 Input: 1 + (4/2) Maximum Depth: 1 Input: ((1)) Maximum Depth: … Read more

## Duplicate even elements in an array

Given an array of numbers, write a program to duplicate the even numbers and return the new array. Example: Input: [2, 4, 1, 5, 2, 3, 8, 9, 10, 4] Output: [2, 2, 4, 4, 1, 5, 2, 2, 3, 8, 8, 9, 10, 10, 4, 4] Input: [2, 4, 6, 8] Output: [2, 2, … Read more

## Minimum Increments to make all array elements unique

Given a sorted array of integers, Write an algorithm to make all array elements distinct or unique by doing minimum increments. Example: Given Input: [2, 2, 3, 5, 6, 6] Unique Array: [2, 3, 4, 5, 6, 7], Minimum Increments: 3 Explanation: Increment 2 to 3, 3 to 4 and 6 to 7. Given Input: … Read more

## Maximum Surpasser in the given array

The “surpasser” of an element in an array is defined as the number of elements that are to the “right” and bigger than itself. Write an algorithm to Find the maximum surpasser of the array. Example: Input array: [2, 7, 5, 5, 2, 7, 0, 8, 1] The “surpassers” are [5, 1, 2, 2, 2, … Read more

## Find the number of pairs with odd XOR

Given an array of integers, write a program to find the number of pairs for which the XOR is an odd number. Example: Input[] = {3, 2, 1} Output: 2 Note: 1 XOR 2 = 3 and 2 XOR 3 = 1 Input[] = {3, 6, 9, 4} Output: 4 Naive Approach: Use nested loops … Read more

## Maximum CPU Load Problem in a jobs list

Given a list of n Jobs with start time, end time and CPU load when it is active at any moment. If all the jobs are running at the same machine then find the maximum CPU load at any time, Also print the time at which the load was maximum. Input: Given a list of … Read more

## Check If Student is eligible for an Attendance Reward

In school a student gets rewarded if he has an attendance record without being absent for more than once or being late for 3 times continuously.  Given a student’s attendance record represented by a string. The record only contains the following three characters: ‘A’ : Absent. ‘L’ : Late. ‘O’ : On-Time. Check whether the … Read more

## Remove Duplicates in a given Sorted Array

Given a sorted array of integers, write a program to remove duplicates in-place by modifying the given array such that all unique integers will be at the beginning of the array, and do not worry about other indexes after the new length. Example: Given Input: [1, 1, 2, 3, 3] Output: [1, 2, 3, 3, … Read more

## Replace Elements with Greatest Element on Right

Given an array of numbers nums[], write ment a function to replace each element of the array with the greatest element present to its right side. Replace the last element with -1.  Example: Input: [4, 5, 2, 25, 13, 16, 8] Output: [25, 25, 25, 16, 16, 8, -1] Input: [4, 5, 2, 25, 13, … Read more

## Count number of pairs in an array with sum = K

Given an array of integers and number K, write a program to find the number of pairs which has sum equal to K. Example: int input [] = {6, 3, 2, 9, 2, 2, 2, 1} int K = 4 Output: 7 int input [] = {5, 5, 5, 5} int K = 10 Output: … Read more

## Count similar words in a given array

Given an array of strings, write a program to count all the similar words.  Similar words: Two words are similar if Has spaces in-between or at the end. Ex: “Apple” and ” A pp le” are similar. Has upper or lower cases. Ex: “APPle” and “apple” are similar. Has special characters. Ex: “app%^L&e” and “@@apple” … Read more