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

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

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

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

Find Election Winner

Election took place with a list of candidates contesting. Each candidate has an id associated with the candidate name. You are given an array of votes represented by ids. Write a program to find the winner of the election. If there is more than one candidate with the highest votes then there would be multiple … Read more