Skip to content

Latest commit

 

History

History
68 lines (46 loc) · 3.19 KB

README.md

File metadata and controls

68 lines (46 loc) · 3.19 KB

algorithm-problems

This project contains small programs which are usually asked in interview, which are related to data structure and algorithms.

1. BinarySearch.java - It is a simple program which search an element from a sorted array using binary search algorithm.

2. CalNumberOfDigit.java - This program simply calculates how many digit are there for a particular integer input

3. DigitToBonary.java - Convert Given Integer to binary format.

4. FindFactors.java - This program will find factors of given integer. e.g input = 18 output = [1, 2, 3, 6, 9, 18]

5. FindOccurenceOfNumber.java - For a given list of integer values , it will find an occurrence of a given particular value. (Using Binary Search) e.g. input = [3,3,4,4,4,4,6,6,6,7,7,8] and you want to find occurrence of 6 output = 3

6. FindSquareRoot.java - Find square root of a given number using binary search.

7. FirstMisstingPositiveInteger.java - If you have an arraylist of given integer then it will find first missing integer. e.g. input - [-9,2,0,-1] Then here first missing positive integer is = 1

8. GCD.java - Find greatest common divisor of given two numbers. e.g Factors of 36 = [1, 2, 3, 4, 6, 9, 12, 18, 36] Factors of 42 = [1, 2, 3, 6, 7, 14, 21, 42] Now greatest common factor between these two numbers = 6. so output will be - 6.

9. LargestNumberFromGivenArray.java - From given list of integer, how can you generate largest integer using all those list integer values ? e.g. input = [54,546,548,60] output = 6054854654

10.LengthOfLastWord.java - For a given string it will print length of last word. e.g. input = kush mukeshbhai Patel now here last work is "Patel" so output = 5

11. MergeInterval.java - Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).

You may assume that the intervals were initially sorted according to their start times.

Example 1: Given intervals [1,3],[6,9] insert and merge [2,5] would result in [1,5],[6,9].

Example 2: Given [1,2],[3,5],[6,7],[8,10],[12,16], insert and merge [4,9] would result in [1,2],[3,10],[12,16].

This is because the new interval [4,9] overlaps with [3,5],[6,7],[8,10]. Make sure the returned intervals are also sorted.

12. MostSignificantNumber.java - It will find most significant number of a given integer. e.g input = 938567 output = 9

13. PalindromeString.java - It will check whether string is palindrome or not

14.PrimeNumbers.java - Find prime numbers from 0 - given number. e.g. input - 17 output - [2, 3, 5, 7, 11, 13, 17]

15.JobSequencingGreedy.java - Here I have used greedy method to solve the problem. Refer https://www.geeksforgeeks.org/job-sequencing-problem/ for better understanding. You can also watch https://youtu.be/zPtI8q9gvX8.

16.KnapSackGreedy.java - Here I have used greedy method to solve the problem. Refer https://youtu.be/oTTzNMHM05I for better understanding.

17.HuffmanCoding.java - HuffmanCoding is basically used for message compression. I solved it using greeedy alog. Refer https://youtu.be/co4_ahEDCho.