Minimum number of adjacent swaps to sort the given array

Given an array of integers, you are allowed to swap only adjacent elements in the array. write a program to find the minimum number of swaps to sort the given array. Example: Input[] : [2, 20, 15, 6, 10] Minimums adjacent swaps required sort the array: 5 Input[] : [10, 3, 4, 2, 5, 7, … Read more Minimum number of adjacent swaps to sort the given array

Check if the given playlist of programs is valid

Problem Statement: Given a playlist that contains the list of intervals with the start time, end time and program id. Write a program to validate whether the playlist is valid or not based on certain conditions.  The playlist will be considered invalid if any of the following is true – If any two programs overlap. … Read more Check if the given playlist of programs is valid

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

Sort the indexes of the array as per the elements of the array

Objective: Given an array, write a java program to sort the indexes of the array according to the elements of the given array ( do not sort the given array) Example: Input Array: [5, 6, 1, 2, 8, 4, 3, 0] Sorted indices as per input array: [7, 2, 3, 6, 5, 0, 1, 4] … Read more Sort the indexes of the array as per the elements of the array

Most frequent word

Objective: Given an array of string, write a program to find the word in the array which appears the maximum number of times. Example: Input: [Algorithms, String, Integer, Integer, Algorithms, String, Integer, Algorithms, String, Algorithms] Most frequent word: Algorithms Naive Approach: Use the nested loops, compare the word from the outer loop with all the … Read more Most frequent word

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

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.

Find if any two intervals overlap in given intervals

Objective: Interval is defined as [start, end]- the start of an interval to the end of the interval. Given a list of Intervals. Your task is to check if any two intervals overlap. Example: Given Interval: [[1,5], [6,10], [12,15], [3,7]] Two intervals are present which intersect Given Interval: [[1,5], [6,10], [12,15]] No intervals overlasx Approach:  … Read more Find if any two intervals overlap in given intervals