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

The largest number can be formed from the given number

Given a number write an algorithm to construct the largest number possible by using the digits of given number. Given number could be a negative number as well.  Example: Given Input: 34277765 Output: 77765432 Given Input: -342765 Output: -234567 Given Input: 0 Output: 0 Given Input: 2034 Output: 4320 Approach: Sorting Check if the given … Read more The largest number can be formed from the given number

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

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