## Replace Elements with Greatest Element on Right

Given an array of numbers nums[], write ment a function to replace each element of the array with the greatest element present to its right side. Replace the last element with -1.  Example: Input: [4, 5, 2, 25, 13, 16, 8] Output: [25, 25, 25, 16, 16, 8, -1] Input: [4, 5, 2, 25, 13, … Read more

## Count similar words in a given array

Given an array of strings, write a program to count all the similar words.  Similar words: Two words are similar if Has spaces in-between or at the end. Ex: “Apple” and ” A pp le” are similar. Has upper or lower cases. Ex: “APPle” and “apple” are similar. Has special characters. Ex: “app%^L&e” and “@@apple” … Read more

## Sort 0’s, the 1’s and 2’s in the given array – Dutch National Flag algorithm | Set – 2

Given an array of numbers, that consists only of three types of integers, which are 0, 1, and 2. Write an algorithm to sort the given array. Example: Input: {2, 1, 2, 0, 1, 0} Output: {0, 0, 1, 1, 2, 2} Input: [0, 0, 2, 0, 2, 1, 0, 1, 2] Output: [0, 0, … Read more

## Sort 0’s, the 1’s, and 2’s in the given array. | Set – 1

Given an array of numbers that consists only of three types of integers, which are 0, 1 and 2. Write an algorithm to sort the given array. Example: Input: {2, 1, 2, 0, 1, 0} Output: {0, 0, 1, 1, 2, 2} Input: [0, 0, 2, 0, 2, 1, 0, 1, 2] Output: [0, 0, … Read more

## Override List Collections Sort Method

Many times we have a list of custom objects and we need to sort these objects. In such cases we need to override the compare function for Collections.sort method. In this article we discuss how to do that. Say we have a list of employees. Each employee has id, name, and salary. Write a function … Read more

## Overlapping sum of two arrays.

Given two arrays of integers. Write a program to find the sum of all the overlapping elements between two arrays. You can consider that there will not be any duplicates in each array individually. Example: A [] : [6, 5, 1, 9, 2, 8, 3] B [] : [3, 7, 9, 2, 4] Overlapping sum … Read more

## Override Arrays Sort Method – Java

Many times we have an array of custom objects and we need to sort these objects. In such cases we need to override the compare function for Arrays.sort method. In this article we discuss how to do that. Say we have a list of employees. Each employee has id, name, and salary. Write a function … Read more

## Pascal Triangle

Given a number N, write a program to print the first N lines of the Pascal triangle. Pascal Triangle: Note: In Pascal’s triangle, each number is the sum of the two numbers directly above it.  (Image reference: Wiki) Approach: Initialize list row and list of lists as all_rows.  We will keep updating the list row … Read more

## Calculate tax on income as per given tax brackets.

Given a list of tax brackets (different tax on different incomes). Write a program to calculate the tax on given income.  Tax bracket is a pair consisting of amount and percentage tax on that amount. If amount is null means, it’s a highest bracket and percentage tax is mentioned will be applied to all the … Read more

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

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

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

## Find the number of pairs with even XOR

Given an array of integers, write a program to find the number of pairs for which the XOR is an even number. Example: Input[] = {3, 2, 1} Output: 1 Note: 1 XOR 3 = 2 Input[] = {3, 6, 9, 4} Output: 2 Naive Approach: Use nested loops and do the xor for each … Read more

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

## Given an array, Find the number of all pairs with even sum

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