## 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

## 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

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

## 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

## 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

## 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

## Number of Contiguous Parking Areas

Problem: Given a building with parking slots. If a spot is free then it is marked by 1 and if the spot is taken by a vehicle then it is marked by 0. Write a program to find the number of free contiguous parking areas in the building. One free parking area can have one … Read more

## Pascal Triangle – Get specific row K

Given a row index K, write a program to print the Kth of Pascal triangle. Note: row index starts from 0. Pascal Triangle: Example:  K = 2 Output: 1, 1 K= 5 Output: 1, 4, 6, 4, 1 Simple Approach: As we discussed here – Pascal triangle, starting calculating the rows from 1 to K … Read more

## Design data structure for players and ranks

Given a list of player names and their scores, design a data structure that can support following modules in optimal time- updateEntry(String name) – Increase the player score with “name” by 1. If no player with name is present then add a player with score 1. getEntryFromRank(int rank) – Get the players with the given … Read more

## Compare two version numbers of a software

Given two versions of a software, write an algorithm to find out which version is the latest. Example: Version A: 1.1.0 Version B: 1.1.1 Given version B latest than version A Version A: 1.2.1 Version B: 1.2.1 Given versions are the same Version A: 2.2.0 Version B: 2.2 Given versions are the same Version A: … Read more

## Minimum number of times String A is repeated to such that B is substring of A

Given a string A consisting of n characters and a string B consisting of m characters, write a function that will return the number of times A must be stated such that B is a substring of the repeated A. If B can never be a substring, return -1. Example: A = ‘abcd’ B =’cdabcdab’ … Read more

## Print all nested directories and files in a given directory – Recursion

Given a source directory, write a recursive program to print all the nested directories and files in the source directory. Example: [Hellojava] [target] original-Hellojava-1.0-SNAPSHOT.jar [classes] [com] [example] [lambda] [demo] Hello.class [maven-archiver] pom.properties Hellojava-1.0-SNAPSHOT.jar pom.xml Hellojava.iml [src] [test] [java] [main] [resources] [java] [com] Hello.java Approach: Check if given file is directory,  if yes then print its … Read more

## Maximum meetings in one room

You have one meeting room at your company. There are N meeting needs to take place. Every meeting has a start time and end time along with the meeting title. Your task is to schedule as many meetings as possible in that conference room with no conflicts.  Example: Meetings: A[ Start Time: 1, End Time: … Read more