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 Design data structure for players and ranks

Maximum Bipartite Matching Problem

Problem: Given a bipartite graph, write an algorithm to find the maximum matching. The maximum bipartite matching solves many problems in the real world like if there are M jobs and N applicants. Each applicant can do some jobs. Your task is to assign these jobs to the applicants so that maximum applicants get the … Read more Maximum Bipartite Matching Problem

Minimum Deletions to make the occurrence of each character unique.

Objective: Given a string, your task is to delete the minimum number of characters in the string so that the count of each character is unique. Example: Input = “aaaaabbbbb” Output: 1 Explanation: In the input string, characters ‘a’ and ‘b’, both occur 5 times. You can delete either one ‘a’ or one ‘b’ to … Read more Minimum Deletions to make the occurrence of each character unique.

Print Top 10 videos from List

Given a list L of video names and their watch rates, write a function that will return the videos with the top 10 watch rates. Video names may appear more than once. Example: Input: [abc : 10] [def : 20] [abc : 15] [ghi : 50] [xyz : 100] [abc : 25] [jkl : 10] … Read more Print Top 10 videos from List

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 Compare two version numbers of a software

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 Minimum number of times String A is repeated to such that B is substring of A

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 Maximum meetings in one room

The number of cycles in a given array of integers.

Objective: Given an array of size N which contains integers from range 0 to N-1. (No duplicates). Write a program to find the number of cycles in the array.  Cycles in Array: Since the array is of size N and elements are from 0 to N-1 without any duplicates means all the elements appear exactly … Read more The number of cycles in a given array of integers.

Check if given sudoku is valid or not

Problem: Given a filled sudoku, write a program to check if sudoku is valid or following all of its rules. SUDOKU rules:  Each column contains all of the digits from 1 to 9 only once. Each row contains all of the digits from 1 to 9 only once. Each of the nine 3×3 sub-grid contains … Read more Check if given sudoku is valid or not

Calculate (x^y)%z without using pow() function

Problem: Given integers x, y, and z. Write a program to calculate (x^y)%z without pow() function. Example: x = 2, y= 5, z = 3 Output: (2 ^ 5) % 3 = 2 x = 5, y= 55, z = 221 Output: (5 ^ 55) % 221 = 112 Approach: Straight forward way to calculate … Read more Calculate (x^y)%z without using pow() function

Efficient Robot Problem – Find Minimum Trips

Problem: There is N number of items that need to be transferred from one place to another by a robot. Each item has a specific weight. The robot can carry maximum weight K in one trip. You need to come up with an algorithm to find out the minimum number of trips that the robot … Read more Efficient Robot Problem – Find Minimum Trips

Find subarray with a sum to given number-2 | Handle negative numbers

Problem: Given an array (positive and negative) and an integer, find the subarray with sum is equal to the given integer.  Note: This problem is an extension of – find the subarray with sum to a Given Value, in which arrays with negative numbers are not handled.  Example: Given input: [25, 12, -14, 22, -19, … Read more Find subarray with a sum to given number-2 | Handle negative numbers

Sort the two dimensional (2D) array – In-place

Problem: Given a two-dimensional array where each individual row is sorted in ascending order. Your task to sort the entire 2d array in ascending order. Write an algorithm for the sorting. Example: Given Array: [[5, 12, 17, 21, 23] [1, 2, 4, 6, 8] [12, 14, 18, 19, 27] [3, 7, 9, 15, 25]] Sorted … Read more Sort the two dimensional (2D) array – In-place

Implement/Design the version control map system

Problem: Implement the version control map system which takes the snapshot of the versions of data. Implement the following functions: put(key, value) – puts the value again the key in the latest version of the map get(key) – get the value of the key for the latest version of the data snapshot() – take a … Read more Implement/Design the version control map system

Given an array, count the number of pairs with a given sum.

Objective: Given an array of integers, write a program to count all the pairs with the given sum. Example: Given array: [1, 5, 7, 1, -1], Sum= 6 Total Pairs: 3 Note: pairs are (1, 5), (5, 1) and (7, -1) Given array: [4, 5, 1, 2, 9, -2, -4], Sum= 5 Total Pairs: 2 … Read more Given an array, count the number of pairs with a given sum.