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

Find departure and destination cities from the 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

Maximum Depth of Valid Nested Parentheses

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

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

Maximum CPU Load Problem

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

Student 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

Count Maximum overlaps in a given list of time intervals

Interval is defined as [start, end]- the start of the interval to the end of the interval. Given the list of Intervals write an algorithm to find the maximum number of intervals overlapping at any point in time. Example: Given Intervals: [[0,2], [3,7], [1,5], [7,8], [4,6]] Maximum overlapping: 3 Explanation: Interval (4, 5) is overlapping … Read more

Remove Duplicates from 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 which has sum equal to 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

Maximum distance from the nearest person.

Given a bench with n seats and few people sitting, You are going to sit on a vacant seat such that the distance between you and the nearest person to you is maximum. On the beach, the occupied seats are represented by 1 and vacant seats are represented by 0. Example: Input: [1, 0, 1, … Read more

Candidate Voting Problem

Given candidates standing for an election, design a data structure that can support the following modules –  1. voteCandidate (candidateName) – Add one vote for the candidate. 2. getTopK ( k ) – This will return top K candidates at that time. It can return more than k candidates if more candidates have the same … Read more