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

Unresolved references error – Django in PyCharm and IntelliJ

This is a known problem for many. If you are seeing “Unresolved references error” for all the imports of Django as in the image below (either in PyCharm or in IntelliJ) then the Django package is missing. Add Django Package in Intellij  Right click on your project and click on the open module setting. Select … Read more Unresolved references error – Django in PyCharm and IntelliJ

Construct the Largest number from the given digits

Given a set of digits, write an algorithm to construct the largest number possible by appending the given digits. Example: Given Digits: [9, 1, 9, 2, 8, 4, 2] largest number: 9984221 Given Digits: [1, 2, 5, 6, 7] largest number: 76521 Approach: Sorting Sort the given array in descending order. Initialize result = 0. … Read more Construct the Largest number from the given digits

Find Lexicographically smallest or largest substring of size k

Given a string and number k, write a program to find the lexicographically smallest substring of size k. Note: This problem can also be asked as find the lexicographically largest substring of size k Example: Input: “tutorial”, k = 2 Output: Smallest Lexicographically SubString: “al” Input: “tutorial”, k=3 Smallest Lexicographically SubString: “ial” Input: horizon, k=2 … Read more Find Lexicographically smallest or largest substring of size k

Largest word in dictionary by removing a few characters from the given string

Given a dictionary (list of words) and an input string K. Find the largest word in the dictionary which can be obtained by deleting a few characters in the input string K. Example: Dictionary: [tutorial, horizon, trial, zon] Input: taucdtorgibalbhsoariazaonzaqn Output: tutorial Dictionary: [tutorial, horizon, trial, zon], Input: attroialled Output: trial Approach: Please read – … Read more Largest word in dictionary by removing a few characters from the given string

Check if one string is a subsequence of another string.

Objective: Given two strings, write a program to check if any of the given string is a subsequence of another string. Example if given strings are A and B then EITHER A is subsequence of B OR B is subsequence of A, program should return true. Example: A = “horizon” B = “abhordizaonr” Output: true … Read more Check if one string is a subsequence of another string.

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

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.

Two Sum Problem

Objective: Given an array of integers, and k. Write a program to find indexes of two elements in an array which sum is equal to K. Example: Given array: [5, 4, 7, 3, 9, 2], Sum = 13 Output: Found indexes are: 4 and 1 Given array: [1, 2, 3, 4, 5], Sum = 9 … Read more Two Sum Problem

Given an array, find the number of all pairs with odd sum.

Objective: Given an array of integers, write a program to find the number of pairs with even odd. Example: Given Input: [1, 2, 3, 4] Number of odd pairs: 4 Note: (1, 2), (1, 4), (2, 3) and (3, 4) Given Input: [6, 7, 1, 3, 2, 5, 4] Number of odd pairs Naive approach: … Read more Given an array, find the number of all pairs with odd sum.

Sum of distinct elements among two given sets

Objective: Given two sets of elements, find the sum of all distinct elements from the set. In other words, find the sum of all elements which are present in either of the given set.  This problem is also asked as – Find sum of non-overlapping numbers in two given sets. Example: Set 1 : [3, … Read more Sum of distinct elements among two given sets

Insert a node in the given sorted linked list.

Objective: Given a linked list in which nodes are sorted in ascending order. Write an algorithm to insert a given node into the linked list so that all the nodes in the list will maintain the sorted order. Example:  Given Linked List:  -> 2, Insert node: 6 New List:  -> 2 -> 6 Given Linked … Read more Insert a node in the given sorted linked list.