# Category Archives: Misc

View Miscellaneous problems

## Prime factors of a number. [Prime Factorization]

Question: Given an integer N, find all the prime factors of the number. Input: N = 45 Output: 3 5 Finding prime factors of any numbers is a very important concept in number theory. One sample problem is available here in which we have to find the largest prime factor. The mathematical concept behind this problem is simple.… Read More »

## Find the first N prime numbers. (Method 4) [Sieve of Eratosthenes]

Question: Given an integer N, find the prime numbers in that range from 1 to N. Input: N = 25 Output: 2, 3, 5, 7, 11, 13, 17, 19, 23 We have several ways of finding prime numbers. Some of the methods are discussed in the these posts. Method 1 Method 2 Method 3 In this post we… Read More »

## Find the sum of even Fibonacci numbers.

Question: Find the sum of even fibonacci numbers upto a limit N. Input:100 Output: 44 Fibonacci numbers are a miracle of Math and are defined as:- f(0) = 0 f(1) = 1 f(n) = f(n-1) + f(n-2); for n>=2 Thus the Fibonacci series can be given as 0, 1, 1, 2, 3, 5, 8, 13, 21… Let us… Read More »

## [Hackerrank] – Multiples of 3 and 5

Question: If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below ‘N’ Input: N = 100 Output: 2318 The most naive approach to solve this problem… Read More »

## Convert a number into a string of words

Question: Given an integer N, convert it into a string of words. Input: N = 345 Output: three hundred forty five This is one of the most common problems that we come across in out daily lives. We need to input a number from the user and print it in words. First, we perform a number of checks… Read More »

## Common String Algorithms

In this post, I would try to implement the following string-related algorithm questions. I would like to implement these using Java and try to make additional comments which I think that are useful for understanding the implementations of some type of data structures in Java programming language. Non Repeated Characters in String : Return the unique characters in… Read More »

## Find the first N prime numbers. (Method 3)

Question: Given an integer N, find the prime numbers in that range from 1 to N. Input: N = 25 Output: 2, 3, 5, 7, 11, 13, 17, 19, 23 We discussed the basic approaches to find the first N prime numbers in these posts Find the first N prime numbers (Method 1) Find the first N prime… Read More »

## Find the first N prime numbers. (Method 2)

Question: Given an integer N, find the prime numbers in that range from 1 to N. Input: N = 25 Output: 2, 3, 5, 7, 11, 13, 17, 19, 23 We discussed the most basic approach to find the first N prime numbers in this post. Find the first N prime numbers. (Method 1) Please go through the… Read More »

## Find the first N prime numbers. (Method 1)

Question: Given an integer N, find the prime numbers in that range from 1 to N. Input: N = 25 Output: 2, 3, 5, 7, 11, 13, 17, 19, 23 Today let us discuss about a very common but very interesting problem “To find prime numbers in first N Natural numbers “. I will be taking here a… Read More »

## Determine if 2 rectangles overlap

Question: You are given two axis-aligned rectangles. You have to determine if these rectangles overlap each other or not. Rectangle 1 : P1 (x, y), P2 (x,y) Rectangle 2 : P3 (x,y), P4 (x,y) In this problem statement, we are given co-ordinates for 2 rectangles and we have to determine if they overlap or not. In a way… Read More »