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

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

## Find all the Armstrong numbers in the given range

Objective: Given a range of integers, wrote a program to find all the Armstrong numbers in that range. What is Armstrong number: Determine the number of digits in the number. Call that n. Then take every digit in the number and raise it to the n power. Add all those together, and if your answer … Read more

## Round Price Problem

Problem Statement: When customers book an Airbnb the total price, which includes base price + service fee + cleaning fee. all these prices are in decimals. Write an algorithm to round each price such that the sum of the prices equals the round of the total sum of all decimal prices and minimize the rounding. … Read more

## K-Means Algorithm

The algorithm of kMeans is an unsupervised learning algorithm for clustering a set of items into groups. Given a set of multi-dimensional items and a number of clusters, k, we are tasked of categorizing the items into groups of similarity. The centers of these groups are called means. Overview The algorithm in pseudocode: Input: Data … Read more

## Longest contiguous character in a given String – O(N) Solution

Objective: Given an input string, write an algorithm to find the longest contiguous character or in other words, find a maximum consecutive character in the string. Example: Input: “aaabbccccddbbaaa” Output: c, count = 4 Input: “bbbbb” Output: b, count=5 Approach: Naive Approach:  Naive Approach: Use  two nested loops The outer loop to fix it on … Read more

## Product of all Unique elements in a given array.

Objective: Given an array of integers which contains duplicates as well. Write a program to find the product of all unique elements in the array. This problem is also referred as find the product  of all distinct elements in the array Example: [] arrA = {1, 6, 4, 3, 2, 2, 3, 8, 1}; Output … Read more

## Multiply with power of 2 without using pow() or * operator

Objective: Given a number n and k, Calculate n * k2 without using pow() or *operator. Example: N = 3, k = 4 N*k2 = 48 Approach: Bit Manipulation Left shift the number N by k. For example, N = 3 Bit representation: 0 1 1 Left shift by k = 4 0 1 1 … Read more

## Dynamic Programming – Maximum Subarray Problem

Objective:  The maximum subarray problem is the task of finding the contiguous subarray within a one-dimensional array of numbers which has the largest sum. Example: int [] A = {−2, 1, −3, 4, −1, 2, 1, −5, 4}; Output: contiguous subarray with the largest sum is 4, −1, 2, 1, with sum 6. Approach: Earlier we have seen … Read more

## Level Order Traversal in Zig Zag pattern OR Print in Spiral Pattern

Objective: Given a binary Tree, Do Level Order Traversal in Zig Zag pattern OR Print in Spiral

Input: A Binary Tree

Output: Order Traversal in Zig Zag pattern OR Print in Spiral. Level Order Traversal in Zig Zag pattern OR Print in Spiral