├── .DS_Store ├── .gitignore ├── Algorithms ├── .DS_Store ├── Arrays │ ├── Bubble_sort │ │ └── SortBubble.java │ ├── Kadane │ │ ├── Kadane_algo.java │ │ ├── cpp-kadane'salgorithm-O(n)-2.cpp │ │ ├── kadane.py │ │ ├── kadane_algo.cpp │ │ └── kadane_algo.py │ ├── MatrixRotation │ │ └── matRotate.py │ ├── Mazepath │ │ └── mazepath.java │ ├── Subsequence │ │ ├── print_subsequence.cpp │ │ └── print_subsequence.py │ └── kthSmallestElement │ │ └── kthSmall.py ├── Dynamic Programming │ ├── 0-1_Knapsack_Problem.py │ ├── Fractional_Knapsack_Problem.cpp │ ├── Fractional_Knapsack_Problem.java │ ├── Knapsack_with_repitition.cpp │ ├── Longest Common Subsequence │ │ └── CPP │ │ │ └── longestCommonSubseq.cpp │ ├── Longest Common Substring │ │ └── CPP │ │ │ └── longestCommonSubstring.cpp │ ├── Longest Increasing Subsequence │ │ └── CPP │ │ │ ├── LongestIncreasingSubsequence.java │ │ │ └── longestIncreasingSubsequence.cpp │ ├── MakeChange.java │ ├── MatrixChainMultiplication.java │ ├── edit_distance.py │ ├── fractional_knapsack.c │ ├── fractional_knapsack.py │ ├── generate_parentheses │ │ └── generate_parentheses.py │ ├── longest_common_subsequence.py │ ├── longest_sum_subarray │ │ └── python │ │ │ ├── kadane.py │ │ │ └── readme.md │ ├── minimum_number_of_jumps │ │ └── python │ │ │ ├── minjumps.py │ │ │ └── readme.md │ └── rod_cutting_problem.py ├── Greedy Algorithm │ ├── Activity_Selection_Problem.py │ ├── Egyptian Fraction.cpp │ ├── Fractional_Knapsack_Problem.cpp │ ├── README.md │ └── Travelling_Salesman_Problem.cpp ├── Kadane.cpp ├── LPS_O(n) ├── Maths │ ├── .DS_Store │ ├── Base Conversion │ │ ├── C │ │ │ └── base_conversion.c │ │ └── binary_number │ │ │ ├── check_multple_of3.c │ │ │ └── readme.md │ ├── Catalan number │ │ ├── catalan_no.c │ │ └── catalan_num.py │ ├── Chinese_Remainder_Theorem │ │ ├── .DS_Store │ │ └── CPP │ │ │ └── chinese_remainder_theorem.cpp │ ├── Computational Geometry │ │ ├── .DS_Store │ │ ├── Python │ │ │ └── COMPUTATIONAL_GEOMETRY.py │ │ └── README.md │ ├── Euclidean GCD │ │ ├── C │ │ │ ├── Euclidean_GCD_using_Recursion.c │ │ │ ├── GCD.c │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── euclidean_gcd.cpp │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── EuclideanGCD.java │ │ │ └── readme.md │ │ ├── Python │ │ │ ├── euclidean_gcd.py │ │ │ └── readme.md │ │ └── README.md │ ├── Factorial │ │ ├── Java │ │ │ └── Factorial.java │ │ ├── README.md │ │ ├── cpp │ │ │ └── factorial.cpp │ │ └── python │ │ │ └── factorial.py │ ├── Fibonacci series │ │ ├── BASH │ │ │ └── Fibonacci.sh │ │ ├── C │ │ │ ├── Fibonacci_series.c │ │ │ ├── a.out │ │ │ ├── mycode.c │ │ │ ├── n_terms_fibonacci.c │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── Fibonacci_DP.cpp │ │ │ ├── fibonacci_series.cpp │ │ │ ├── opt_fibonacci_no.cpp │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── Fibonacci.java │ │ │ └── readme.md │ │ ├── Python │ │ │ ├── Fibonacci_Sequence.py │ │ │ ├── Fibonnacci.py │ │ │ └── readme.md │ │ └── README.md │ ├── Magic Number │ │ ├── Magic Number.py │ │ ├── MagicNo.py │ │ ├── MagicNumber.java │ │ ├── Nodejs │ │ │ └── MagicNumber.js │ │ ├── magic_number.c │ │ └── magic_number.cpp │ ├── Modular Exponentiation │ │ ├── C │ │ │ ├── ModularExponentiation.c │ │ │ └── README.md │ │ ├── CPP │ │ │ └── ModularExponentiation.cpp │ │ ├── Java │ │ │ ├── ModularExponentiation.java │ │ │ └── README.md │ │ └── Python │ │ │ ├── ModularExponentiation.py │ │ │ └── README.md │ ├── Pallindrome number │ │ ├── C │ │ │ ├── Palindrome.c │ │ │ ├── palindrome_number.c │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── palindrome.cpp │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── PallindromeNumber.java │ │ │ ├── Pallindrome_number.java │ │ │ ├── Pallindrome_string.java │ │ │ ├── palindrome.java │ │ │ └── readme.md │ │ ├── Python │ │ │ ├── Palindrome.py │ │ │ ├── Pallindrome_number.py │ │ │ └── readme.md │ │ └── README.md │ ├── Perfect Number │ │ ├── .DS_Store │ │ ├── C │ │ │ ├── PerfectNumber.c │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── perfectnumber.cpp │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── PerfectNumber.java │ │ │ └── readme.md │ │ ├── Python │ │ │ ├── Perfect_Number.py │ │ │ ├── perfect.py │ │ │ └── readme.md │ │ ├── README.md │ │ ├── a.out │ │ ├── perfect number.c │ │ ├── perfect_num.cpp │ │ └── perfectno.cpp │ ├── Perfect number │ │ ├── C │ │ │ ├── PerfectNumber.c │ │ │ ├── perfect_number.c │ │ │ └── readme.md │ │ ├── CPP │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── PerfectNumber.java │ │ │ └── readme.md │ │ └── Python │ │ │ ├── Perfect_Number.py │ │ │ └── readme.md │ ├── Polite number │ │ ├── polite_number.cpp │ │ ├── polite_number.java │ │ └── polite_number.py │ ├── README.md │ ├── Sieve Eratosthenes │ │ └── CPP │ │ │ ├── SieveEratosthenes.cpp │ │ │ └── sieve │ ├── Sieve of Eratosthenes algorithm │ │ ├── README.md │ │ ├── cpp │ │ │ └── Sieve of Eratosthenes algorithm.cpp │ │ ├── java │ │ │ └── Sieve ofEratosthenes algorithm.java │ │ ├── sieve.c │ │ └── sieve.py │ ├── armstrong-number │ │ ├── README.md │ │ ├── armstrong-number.cpp │ │ └── armstrong-number.py │ ├── factorial │ │ ├── factorial.cpp │ │ └── factorial.py │ └── pure numbers │ │ └── pure_numbers.cpp ├── Recursion │ ├── palindrome │ │ ├── palindrome.cpp │ │ ├── palindrome.java │ │ └── palindrome.py │ └── tower_of_hanoi.c ├── Searching & Sorting │ ├── .DS_Store │ ├── Binary Search │ │ ├── Binary_Burbble_Search.cpp │ │ ├── Binary_Search.py │ │ ├── C │ │ │ ├── binary_search.c │ │ │ └── binary_search_iter.c │ │ ├── CPP │ │ │ ├── BinarySearchRecursive.cpp │ │ │ └── Binary_Search_Iter_Recur.cpp │ │ ├── README.md │ │ ├── Ruby │ │ │ └── binary_search.rb │ │ ├── a.out │ │ ├── binary_Search_Iterative.cpp │ │ ├── binary_search.java │ │ ├── binary_search_iter.c │ │ ├── binary_search_iterative.py │ │ └── binary_search_iterative_recursive.java │ ├── Bogo Sort │ │ ├── bogo.py │ │ ├── bogosort.py │ │ └── sort.py │ ├── Breadth-First-Search.cs │ ├── Bubble Sort in Java │ │ └── BubbleSort.java │ ├── Bubble Sort │ │ ├── .DS_Store │ │ ├── BubbleSort.java │ │ ├── BubbleSort.py │ │ ├── Bubble_sort.c │ │ ├── Bubble_sort.cpp │ │ ├── Bubblesort.java │ │ ├── README.md │ │ ├── bubbleSort.cpp │ │ ├── bubbleSort.java │ │ ├── bubble_sort.c │ │ ├── bubble_sort.cs │ │ ├── bubble_sort.java │ │ └── bubble_sort.py │ ├── BucketSort.cpp │ ├── Counting Sort │ │ ├── Counting Sort.cpp │ │ ├── Java │ │ │ └── CountingSort.java │ │ ├── Python │ │ │ ├── counting-sort.py │ │ │ └── counting_sort.py │ │ ├── README.md │ │ ├── Ruby │ │ │ └── Counting_sort.rb │ │ └── countingsort.py │ ├── Depth First Search │ │ ├── DFS.java │ │ └── depth_first_search.cpp │ ├── Exponential Search │ │ └── exponential_search.py │ ├── Fibonacii Search │ │ ├── fibinacci_search.py │ │ └── fibonacci_search.cpp │ ├── Heap Sort │ │ ├── .DS_Store │ │ ├── HeapSort.java │ │ ├── Heapsort.c │ │ ├── README.md │ │ ├── heap_sort.c │ │ └── heap_sort.cpp │ ├── Insertion Sort │ │ ├── .DS_Store │ │ ├── C++ │ │ │ └── InsertionSort.cpp │ │ ├── C │ │ │ └── insertion_sort.c │ │ ├── Insertion-Sort.c │ │ ├── Java │ │ │ └── InsertionSort.java │ │ ├── Python │ │ │ ├── .DS_Store │ │ │ └── InsertionSort.py │ │ ├── README.md │ │ ├── insertion sort.cpp │ │ ├── insertion_sort.cpp │ │ ├── insertion_sort.py │ │ └── insertion_sort_python.py │ ├── Interpolation Search │ │ └── interpolation_search.py │ ├── Jump Search │ │ └── jump_search.py │ ├── Linear Search │ │ ├── LinearSearch.java │ │ ├── Linear_search.py │ │ ├── README.md │ │ ├── linear_search.c │ │ └── linearsearch.java │ ├── Merge Sort │ │ ├── MergeSort.java │ │ ├── MergeSort.py │ │ ├── README.md │ │ ├── mergeSort.cpp │ │ └── merge_sort.c │ ├── Pancake Sort │ │ └── pancakesort.py │ ├── PigeonHole Sort │ │ └── piegonhole.sort │ ├── QuickSort │ │ ├── .DS_Store │ │ ├── QuickSort.py │ │ ├── QuickSort_2.py │ │ ├── README.md │ │ ├── quickSort.cpp │ │ ├── quickSort.java │ │ ├── quick_sort.c │ │ └── quick_sort.py │ ├── README.md │ ├── Radix Sort │ │ ├── README.md │ │ ├── Radix_Sort.cpp │ │ ├── Radixsort.py │ │ └── radix_sort.c │ ├── Selection Sort │ │ ├── .DS_Store │ │ ├── C++ │ │ │ └── SelectionSort.cpp │ │ ├── C │ │ │ ├── .DS_Store │ │ │ └── selectionsort.c │ │ ├── Java │ │ │ └── SelectionSort.java │ │ ├── Python │ │ │ ├── .DS_Store │ │ │ └── SelectionSort.py │ │ └── selectionsort.cpp │ ├── Shell Sort │ │ ├── .DS_Store │ │ ├── ShellSort.java │ │ ├── shellsort.cpp │ │ └── shellsort.py │ ├── Time Sort │ │ └── timsort.cpp │ └── shell sort │ │ └── shell_sort.cpp ├── String │ ├── .DS_Store │ ├── BoyerMoore │ │ └── BoyerMoore.c │ ├── KMP │ │ └── CPP │ │ │ └── KMP.cpp │ ├── NaiveString │ │ └── NaiveSearch.java │ ├── RabinKarp │ │ └── RabinKarp.c │ ├── StringReverse │ │ └── strRev.py │ ├── Sum of Subset │ │ └── sumofsubset.py │ ├── dnapatternmatching │ │ ├── dnapattern.py │ │ └── readme.md │ └── run-length-encoding │ │ ├── readme.md │ │ └── rle.c ├── Tree │ └── printLeafNodes │ │ └── cpp │ │ └── Print all leaf nodes of a Binary Tree from left to right.cpp ├── divide_and_conquer │ ├── divide_and_conquer.py │ └── readme.md ├── largest_sum_of_alternate.md └── largest_sum_of_alternate.py ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ClassicalQuestions.md ├── Company Specific Interview Questions ├── .DS_Store ├── Airbnb │ ├── .DS_Store │ ├── Questions │ │ ├── AddStrings.md │ │ ├── AddTwoNumbers.md │ │ ├── BinarySearchTree.md │ │ ├── HappyNumber.md │ │ ├── MergeSort.md │ │ ├── MiniParser.md │ │ ├── RegularExpression.md │ │ ├── SingleNumber.md │ │ ├── TwoSum.md │ │ └── Validparentheses.md │ ├── README.md │ └── Solutions │ │ ├── .DS_Store │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ ├── BinarySearchTree.cpp │ │ ├── MergeSort.cpp │ │ ├── README.md │ │ ├── TwoSum.cpp │ │ ├── Validparentheses.cpp │ │ └── twoSum.cpp │ │ ├── Java │ │ ├── README.md │ │ ├── TwoSum.java │ │ └── ValidParantheses.Java │ │ └── Python │ │ ├── README.md │ │ └── TwoSum.py ├── Amazon │ ├── .DS_Store │ ├── README.md │ └── Solutions │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ ├── README.md │ │ ├── merge_without_extra_space.c │ │ └── solve_sudoku │ │ ├── Java │ │ ├── LowestCommonAncestor.java │ │ └── README.md │ │ └── Python │ │ └── README.md ├── Apple │ ├── .DS_Store │ ├── README.md │ └── Solutions │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ └── README.md │ │ ├── Java │ │ └── README.md │ │ └── Python │ │ └── README.md ├── Dropbox │ ├── .DS_Store │ ├── README.md │ └── Solutions │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ └── README.md │ │ ├── Java │ │ └── README.md │ │ └── Python │ │ └── README.md ├── Facebook │ ├── .DS_Store │ ├── README.md │ └── Solutions │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ └── README.md │ │ ├── Java │ │ └── README.md │ │ └── Python │ │ └── README.md ├── Google │ ├── .DS_Store │ ├── Questions │ │ ├── Counting in BST.md │ │ ├── Egg Drop.md │ │ ├── Find the Odds.md │ │ ├── Get and Set.md │ │ ├── Jump Num.md │ │ ├── Max Dif.md │ │ ├── Sum to Num S.md │ │ ├── Triplet check.md │ │ ├── Valid.md │ │ └── Word Sequence.md │ ├── README.md │ └── Solutions │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ ├── DNA.cpp │ │ ├── README.md │ │ └── Word_Break.cpp │ │ ├── Java │ │ └── README.md │ │ └── Python │ │ ├── README.md │ │ ├── google_find_odds.md │ │ ├── google_find_odds.py │ │ ├── valid.md │ │ └── valid.py ├── Microsoft │ ├── .DS_Store │ ├── README.md │ └── Solutions │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ └── README.md │ │ ├── Java │ │ └── README.md │ │ └── Python │ │ └── README.md ├── Stripe │ ├── .DS_Store │ ├── README.md │ └── Solutions │ │ ├── C │ │ └── README.md │ │ ├── Cpp │ │ └── README.md │ │ ├── Java │ │ └── README.md │ │ └── Python │ │ └── README.md └── Uber │ ├── .DS_Store │ ├── README.md │ └── Solutions │ ├── C │ └── README.md │ ├── Cpp │ └── README.md │ ├── Java │ └── README.md │ └── Python │ └── README.md ├── Data Structures ├── .DS_Store ├── AES │ └── AES.java ├── AVL Tree │ ├── Avl.py │ ├── Avltree.py │ ├── avl.c │ ├── avl.cpp │ └── avl.java ├── Adjacency matrix │ ├── C │ │ └── readme.md │ ├── CPP │ │ └── readme.md │ ├── Java │ │ └── readme.md │ └── Python │ │ ├── adjacency_matrix.py │ │ └── readme.md ├── Backtracking │ └── N-queen-problem.cpp ├── Circular Linked List │ ├── C │ │ └── readme.md │ ├── CPP │ │ └── readme.md │ ├── Java │ │ ├── CircularSinglyLinkedList.java │ │ └── readme.md │ └── Python │ │ ├── circular_linked_list.py │ │ ├── circularlinkedlist.py │ │ └── readme.md ├── Circular Queue │ └── C │ │ └── circular-queue.c ├── Deque │ └── Python │ │ └── deque.py ├── Disjoint Sets │ ├── C │ │ └── readme.md │ ├── CPP │ │ ├── disjoint_sets.cpp │ │ └── readme.md │ ├── Java │ │ ├── DisjointSets.java │ │ └── readme.md │ └── Python │ │ ├── DisjointSets.py │ │ └── readme.md ├── Doubly Linked List │ ├── C │ │ ├── Doubly linked list.c │ │ ├── doubly_linked_list.c │ │ └── readme.md │ ├── CPP │ │ ├── doublyLL.cpp │ │ └── readme.md │ ├── Java │ │ ├── Doubly Linked List.java │ │ └── readme.md │ └── Python │ │ ├── doubly_linked_list.py │ │ └── readme.md ├── Dynamic Array │ ├── C │ │ ├── dynamic_array.c │ │ └── readme.md │ ├── CPP │ │ ├── dynamic_array.cpp │ │ └── readme.md │ ├── Java │ │ ├── DynamicArray.java │ │ └── readme.md │ └── Python │ │ ├── dynamic_array.py │ │ └── readme.md ├── Fibonacci Heap │ ├── .DS_Store │ ├── C │ │ ├── Fibbonacci.c │ │ └── readme.md │ ├── CPP │ │ └── readme.md │ ├── Java │ │ └── readme.md │ └── Python │ │ ├── FibonacciHeap.py │ │ ├── fibonacci.py │ │ └── readme.md ├── Graph Traversal │ ├── .DS_Store │ ├── Bellman Ford Algorithm │ │ ├── README.md │ │ ├── bellman_ford_algorithm.cpp │ │ └── bellmanford.py │ ├── Breadth First Search │ │ ├── BreadthFirstSearch.py │ │ ├── README.md │ │ ├── bfs.c │ │ └── bfs.cpp │ ├── Depth First Search │ │ ├── DepthFirstSearch.py │ │ ├── README.md │ │ ├── dfs.c │ │ ├── dfs.cpp │ │ ├── dfs.java │ │ └── dfs.py │ ├── Dijkstra's Algorithm │ │ ├── README.md │ │ └── dijkstras_algorithm.cpp │ ├── Floyd-Warshall Algorithm │ │ ├── README.md │ │ ├── floyd_warshal.java │ │ └── floyd_warshall.cpp │ ├── Kruskals Algorithms │ │ ├── README.md │ │ ├── kruskal_algo.java │ │ └── kruskals_algorithm.cpp │ ├── Prim's Algorithms │ │ ├── Prims.c │ │ └── README.md │ ├── README.md │ └── Topological Sort │ │ └── README.md ├── Graph │ └── C │ │ ├── floydwarshall.c │ │ └── readme.md ├── Graphs │ ├── Belmon Ford Algorithm │ │ ├── C │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── belmonford.c │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── bellman_ford_algo.java │ │ │ └── readme.md │ │ └── Python │ │ │ └── readme.md │ ├── Breadth First Search │ │ ├── C │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── bfs.cpp │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── BreadthFirstSearch.java │ │ │ └── readme.md │ │ └── Python │ │ │ └── readme.md │ ├── Cycle Detection │ │ ├── Directed Graph │ │ │ ├── CPP │ │ │ │ └── cycle_detection_directed.cpp │ │ │ ├── Java │ │ │ │ └── cycle_detection_directed.java │ │ │ └── Python │ │ │ │ └── cycle_detection_directed.py │ │ └── Undirected Graph │ │ │ ├── C │ │ │ └── cycle_detection_undirected.c │ │ │ ├── CPP │ │ │ └── cycle_detection_undirected.cpp │ │ │ ├── Java │ │ │ └── cycle_detection_undirected.java │ │ │ └── Python │ │ │ └── cycle_detection_undirected.py │ ├── Depth First Search │ │ ├── C │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── dfs.cpp │ │ │ └── readme.md │ │ ├── Java │ │ │ └── readme.md │ │ └── Python │ │ │ └── readme.md │ ├── Dijkstra's Algorithm │ │ ├── C │ │ │ └── readme.md │ │ ├── CPP │ │ │ └── readme.md │ │ ├── Java │ │ │ ├── Dijkstra.java │ │ │ └── readme.md │ │ └── Python │ │ │ └── readme.md │ ├── Floyd-Warshall Algorithm │ │ ├── C │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── FW.cpp │ │ │ ├── a.out │ │ │ └── readme.md │ │ ├── Java │ │ │ └── readme.md │ │ └── Python │ │ │ ├── floyd.py │ │ │ └── readme.md │ ├── Implementation of BFS using adjacency matrix │ │ └── c++ │ │ │ └── Implementation of BFS using adjacency matrix.cpp │ ├── Kruskal's Algorithm │ │ ├── C │ │ │ ├── kruskals.c │ │ │ └── readme.md │ │ ├── CPP │ │ │ └── readme.md │ │ ├── Java │ │ │ └── readme.md │ │ └── Python │ │ │ └── readme.md │ ├── Prim's Algorithm │ │ ├── C │ │ │ └── readme.md │ │ ├── CPP │ │ │ └── readme.md │ │ ├── Java │ │ │ └── readme.md │ │ └── Python │ │ │ └── readme.md │ ├── Tarjan's algorithm │ │ └── Tarjan.java │ ├── Topological Sort │ │ ├── C │ │ │ └── readme.md │ │ ├── CPP │ │ │ ├── TopologicalSort.cpp │ │ │ └── readme.md │ │ ├── Java │ │ │ └── readme.md │ │ └── Python │ │ │ └── readme.md │ └── ford_fulkerson_maximum_flow │ │ ├── FordFulkersonUsingBfs.java │ │ ├── ford_fulkerson.cpp │ │ ├── ford_fulkerson_using_bfs.cpp │ │ └── ford_fulkerson_using_bfs.py ├── Hash Tables │ ├── C │ │ └── readme.md │ ├── CPP │ │ └── readme.md │ ├── Java │ │ └── readme.md │ └── Python │ │ └── readme.md ├── Heap │ ├── C │ │ ├── heap.c │ │ ├── maxHeap.cpp │ │ └── readme.md │ ├── CPP │ │ ├── heap.cpp │ │ └── readme.md │ ├── Java │ │ ├── Heap.java │ │ └── readme.md │ └── Python │ │ ├── Heap.py │ │ └── readme.md ├── Palindrome │ ├── C_palindrome.c │ ├── Cpp_palindrome.cpp │ ├── Java_palindrome.java │ └── Python_palindrome.py ├── Priority Queue │ ├── C │ │ └── readme.md │ ├── CPP │ │ └── readme.md │ ├── Java │ │ ├── Main.java │ │ └── readme.md │ └── Python │ │ ├── priority_queue.py │ │ └── readme.md ├── Queue │ ├── C │ │ ├── queue.c │ │ └── readme.md │ ├── CPP │ │ ├── Queue.cpp │ │ └── readme.md │ ├── Java │ │ ├── Queue.java │ │ ├── StaticQueueinjava.java │ │ └── readme.md │ ├── Python │ │ ├── Queue.py │ │ ├── queue.py │ │ ├── queueinpy.py │ │ ├── readme.md │ │ └── simple_queue.py │ └── Ruby │ │ └── queue.rb ├── Singly Linked List │ ├── C │ │ ├── readme.md │ │ └── singlylinkedlist.c │ ├── CPP │ │ ├── readme.md │ │ └── singlylinkedlist.cpp │ ├── Java │ │ ├── SinglyLinkedList.java │ │ └── readme.md │ └── Python │ │ ├── SinglyLinkedList.py │ │ ├── linked_list.py │ │ ├── readme.md │ │ └── singly_linked_list.py ├── Stack │ ├── C │ │ ├── dynamic_memory_allocation │ │ │ ├── readme.md │ │ │ └── stack.c │ │ ├── readme.md │ │ ├── stack.c │ │ └── stack2.c │ ├── CPP │ │ ├── Stack.CPP │ │ └── readme.md │ ├── Java │ │ ├── Stack.java │ │ └── readme.md │ └── Python │ │ ├── Stack.py │ │ ├── python_stack_implementation.py │ │ └── readme.md ├── Tree Traversal │ ├── .DS_Store │ ├── AVL Tree │ │ └── README.md │ ├── Binary Search Tree │ │ ├── .DS_Store │ │ ├── BST.py │ │ ├── Python │ │ │ ├── 1.Search.py │ │ │ └── 2.Insert.py │ │ └── README.md │ ├── Depth of the Tree │ │ └── README.md │ ├── Fenwick Tree │ │ ├── README.md │ │ ├── a.out │ │ └── fenwick_tree.cpp │ ├── Height of the Tree │ │ └── README.md │ ├── In-Order Traversal │ │ ├── README.md │ │ ├── inorder.c │ │ ├── inorder.cpp │ │ ├── inorder.js │ │ └── inorder.py │ ├── Lowest Common Ancestor in BST │ │ ├── .DS_Store │ │ └── c │ │ │ └── Lowest Common Ancestor in BST using C++.cpp │ ├── Post-Order Traversal │ │ ├── README.md │ │ ├── postorder.c │ │ ├── postorder.cpp │ │ ├── postorder.js │ │ └── postorder.py │ ├── Pre-Order Traversal │ │ ├── Preorder.py │ │ ├── README.md │ │ ├── preorder.c │ │ ├── preorder.cpp │ │ └── preorder.js │ ├── README.md │ ├── Segment Tree │ │ └── README.md │ ├── Spanning Tree │ │ ├── README.md │ │ └── Tree Traversal - Shortcut.lnk │ ├── Sum of all leaf nodes │ │ └── Sum of all leaf nodes of binary tree in C++.cpp │ ├── Trie │ │ └── README.md │ └── deleteTree │ │ ├── .DS_Store │ │ └── cpp │ │ └── delete a Tree.cpp └── Trie │ ├── Trie.cpp │ ├── Trie.py │ └── trie.java ├── Factorial.c ├── LICENSE └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/.DS_Store -------------------------------------------------------------------------------- /Algorithms/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Arrays/Kadane/Kadane_algo.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Kadans_Algorithm { 4 | public static void main(String[] args) { 5 | 6 | Scanner sc = new Scanner(System.in); 7 | System.out.println("Enter the size of the array: "); 8 | int n = sc.nextInt(); 9 | System.out.println("Enter the elements of the array: "); 10 | int[] arr = new int[n]; 11 | for (int i = 0; i < n; i++) arr[i] = sc.nextInt(); 12 | int csum = arr[0]; 13 | int osum = arr[0]; 14 | 15 | for (int i = 1; i < arr.length; i++) { 16 | if (csum < 0) { 17 | csum = arr[i]; 18 | } else { 19 | csum += arr[i]; 20 | } 21 | 22 | if (csum > osum) { 23 | osum = csum; 24 | } 25 | } 26 | System.out.println("Max sum is " + osum); 27 | } 28 | } -------------------------------------------------------------------------------- /Algorithms/Arrays/Kadane/kadane.py: -------------------------------------------------------------------------------- 1 | """Find the maximum sum of subarray using Kadane algorithm. 2 | """ 3 | def get_max_sum(arr): 4 | max_sum = float("-inf") 5 | running_sum = float("-inf") 6 | 7 | for a in arr: 8 | running_sum = max(running_sum + a, a) 9 | max_sum = max(max_sum, running_sum) 10 | 11 | return max_sum 12 | 13 | def main(): 14 | n = int(input("Enter the size of the array: ")) 15 | print("Enter the elements of the array") 16 | arr = [] 17 | 18 | for _ in range(n): 19 | arr.append(int(input())) 20 | 21 | print("Max sum is %s", get_max_sum(arr)) 22 | 23 | if __name__ == "__main__": 24 | main() 25 | 26 | -------------------------------------------------------------------------------- /Algorithms/Arrays/Kadane/kadane_algo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void kadane_algo(int arr[], int n) { 5 | 6 | int csum = arr[0]; 7 | int osum = arr[0]; 8 | 9 | for (int i = 1; i < n; i++) { 10 | if (csum < 0) { 11 | csum = arr[i]; 12 | } else { 13 | csum += arr[i]; 14 | } 15 | 16 | if (csum > osum) { 17 | osum = csum; 18 | } 19 | } 20 | 21 | cout << "Max sum is " << osum << endl; 22 | } 23 | 24 | int main() { 25 | 26 | int n; 27 | cout << "Enter the size of the array: "; 28 | cin >> n; 29 | cout << "\nEnter the elements of the array" << endl; 30 | int arr[n]; 31 | 32 | for (int i = 0; i < n; i++) 33 | cin >> arr[i]; 34 | 35 | kadane_algo(arr, n); 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /Algorithms/Arrays/Kadane/kadane_algo.py: -------------------------------------------------------------------------------- 1 | # Function to find the maximum subarray sum 2 | # using Kadane's Algorithm 3 | def kadane_algo(arr): 4 | 5 | csum = osum = arr[0] 6 | for i in range(1, len(arr)): 7 | 8 | if csum < 0: 9 | csum = arr[i] 10 | else: 11 | csum += arr[i] 12 | 13 | if csum > osum: 14 | osum = csum 15 | 16 | print("Max sum is", osum) 17 | 18 | def main(): 19 | 20 | n = int(input("Enter the size of the array: ")) 21 | print("Enter the elements of the array") 22 | arr = [None] * n 23 | 24 | for i in range(n): 25 | arr[i] = int(input()) 26 | 27 | kadane_algo(arr) 28 | 29 | if __name__ == "__main__": 30 | main() 31 | -------------------------------------------------------------------------------- /Algorithms/Arrays/MatrixRotation/matRotate.py: -------------------------------------------------------------------------------- 1 | ''' Rotation of a Square matrix at 90 degree clockwise. 2 | With the least complexity 3 | ''' 4 | l=[[1,2,3,4], 5 | [5,6,7,8], 6 | [9,10,11,12], 7 | [13,14,15,16]] 8 | 9 | N = 4 10 | x = N-1 11 | y = x 12 | 13 | #for square matrix 14 | for i in range(0, x): 15 | for j in range(i,x): 16 | l[j][x], l[i][j] = l[i][j], l[j][x] 17 | l[x][y], l[i][j] = l[i][j], l[x][y] 18 | l[y][i], l[i][j] = l[i][j], l[y][i] 19 | y -= 1 20 | x -= 1 21 | y = x 22 | 23 | for i in l: 24 | print(i) 25 | -------------------------------------------------------------------------------- /Algorithms/Arrays/Subsequence/print_subsequence.py: -------------------------------------------------------------------------------- 1 | # Recursive Function to Generate All Subsequence of integer Array 2 | # curr points to current index of original Array A 3 | # idx points to current index of temporary Array temp 4 | def fun(curr, idx, A, temp): 5 | 6 | if curr == len(A): # If curr has reached to n the print temp array 7 | 8 | for i in range(idx): 9 | print(temp[i], end = "") 10 | print() 11 | return 12 | 13 | fun(curr + 1, idx, A, temp) # Calling function without taking current element 14 | temp[idx] = A[curr] 15 | fun(curr + 1, idx + 1, A, temp) # Calling function after taking current element 16 | 17 | def main(): 18 | 19 | n = int(input("\nEnter number of Array Elements: ")) 20 | A = [None] * n 21 | print("Enter Array Elements:") 22 | 23 | for i in range(n): 24 | A[i] = int(input()) 25 | 26 | temp = [0] * 10000 # temporary array to hold subsequence 27 | print("\nFollowing subsequences of given array are generated:") 28 | fun(0, 0, A, temp) # Function to generate subsequenceS 29 | 30 | if __name__ == "__main__": 31 | main() 32 | -------------------------------------------------------------------------------- /Algorithms/Arrays/kthSmallestElement/kthSmall.py: -------------------------------------------------------------------------------- 1 | #Python program to find the kth smallest element from a list 2 | #Without doing sorting 3 | 4 | 5 | ''' Eg: list is 61, 32, 80, 59, 20 6 | When sorted: 20, 32, 59, 61, 80 7 | 3rd smallest element is: 59''' 8 | 9 | N = int(input('Enter size of list: ')) 10 | 11 | print('Enter elements in list: ') 12 | l = [int(x) for x in input().split(" ")] 13 | 14 | K = int(input('kth element to search: ')) 15 | x = max(l) + 1 16 | ch = [0] * x 17 | 18 | for j in range(0, N): 19 | ch[l[j]] += 1 20 | 21 | for j in range(0, len(ch)): 22 | if ch[j] >= 1: 23 | K -= 1 24 | 25 | if K == 0: 26 | print('Element is: ', j) 27 | break -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/0-1_Knapsack_Problem.py: -------------------------------------------------------------------------------- 1 | ''' Similar to fractional KnapSack except 2 | you cannot break an item, 3 | either pick the complete item, 4 | or don’t pick it (0-1 property).''' 5 | 6 | def maxKnapSack(W , wt , profit , n): 7 | 8 | if n == 0 or W == 0 : 9 | return 0 10 | 11 | # If weight of item is more than capacity W 12 | # then this item cannot be included in the optimal solution 13 | 14 | if (wt[n-1] > W): 15 | return maxKnapSack(W , wt , profit , n-1) 16 | 17 | # return the maximum of two cases: 18 | # (a) item included 19 | # (b) not included 20 | else: 21 | return max(profit[n-1] + maxKnapSack(W-wt[n-1] , wt , profit , n-1), 22 | maxKnapSack(W , wt , profit , n-1)) 23 | 24 | # Driver Program 25 | if __name__ == '__main__': 26 | profit = [60, 100, 120] 27 | wt = [10, 20, 30] 28 | W = 50 29 | n = len(profit) 30 | print(maxKnapSack(W , wt , profit , n)) -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/Longest Common Subsequence/CPP/longestCommonSubseq.cpp: -------------------------------------------------------------------------------- 1 | /* Dynamic Programming C++ implementation of Longest Common Subseq. problem */ 2 | #include 3 | using namespace std; 4 | 5 | int lcs(string X, string Y, int m, int n ) { 6 | int L[m + 1][n + 1]; 7 | int i, j; 8 | 9 | for (i = 0; i <= m; i++) { 10 | for (j = 0; j <= n; j++) { 11 | if (i == 0 || j == 0) 12 | L[i][j] = 0; 13 | 14 | else if (X[i - 1] == Y[j - 1]) 15 | L[i][j] = L[i - 1][j - 1] + 1; 16 | 17 | else 18 | L[i][j] = max(L[i - 1][j], L[i][j - 1]); 19 | } 20 | } 21 | 22 | return L[m][n]; 23 | } 24 | 25 | // main function 26 | int main(){ 27 | 28 | string X,Y; 29 | cout<<"enter first string: "; 30 | cin>>X; 31 | cout<<"\nenter second string: "; 32 | cin>>Y; 33 | 34 | int m = X.size(); 35 | int n = Y.size(); 36 | 37 | cout << "Length of LCS is " 38 | << lcs( X, Y, m, n ); 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/Longest Common Substring/CPP/longestCommonSubstring.cpp: -------------------------------------------------------------------------------- 1 | /* Dynamic Programming C++ implementation of Longest commong substring problem */ 2 | #include 3 | using namespace std; 4 | 5 | int lcs(string X, string Y, int m, int n ) { 6 | int LCSuff[m + 1][n + 1]; 7 | int result = 0; 8 | 9 | for (int i = 0; i <= m; i++) { 10 | for (int j = 0; j <= n; j++) { 11 | if (i == 0 || j == 0) 12 | LCSuff[i][j] = 0; 13 | else if (X[i-1] == Y[j-1]) { 14 | LCSuff[i][j] = LCSuff[i-1][j-1] + 1; 15 | result = max(result, LCSuff[i][j]); 16 | } 17 | else LCSuff[i][j] = 0; 18 | } 19 | } 20 | 21 | return result; 22 | } 23 | 24 | // main function 25 | int main(){ 26 | 27 | string X,Y; 28 | cout<<"enter first string: "; 29 | cin>>X; 30 | cout<<"\nenter second string: "; 31 | cin>>Y; 32 | 33 | int m = X.size(); 34 | int n = Y.size(); 35 | 36 | cout << "Length of LCS is " 37 | << lcs( X, Y, m, n ); 38 | 39 | return 0; 40 | } -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/Longest Increasing Subsequence/CPP/longestIncreasingSubsequence.cpp: -------------------------------------------------------------------------------- 1 | /* Dynamic Programming C++ implementation of LIS problem */ 2 | #include 3 | using namespace std; 4 | 5 | int lis( int arr[], int n ) { 6 | int lis[n]; 7 | 8 | lis[0] = 1; 9 | 10 | for (int i = 1; i < n; i++ ) { 11 | lis[i] = 1; 12 | for (int j = 0; j < i; j++ ) 13 | if ( arr[i] > arr[j] && lis[i] < lis[j] + 1) 14 | lis[i] = lis[j] + 1; 15 | } 16 | 17 | return *max_element(lis, lis+n); 18 | } 19 | 20 | // main function 21 | int main() { 22 | int n; 23 | cout<<"enter size of array: "; 24 | cin>>n; 25 | 26 | int arr[n]; 27 | cout<<"enter elements: \n"; 28 | for(int i=0;i>arr[i]; 29 | 30 | printf("Length of lis is %d\n", lis( arr, n ) ); 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/generate_parentheses/generate_parentheses.py: -------------------------------------------------------------------------------- 1 | def generate_parentheses(n): 2 | memo = {} 3 | return _generate_parentheses(n * 2, 0, memo) 4 | 5 | 6 | def _generate_parentheses(n, l, memo): 7 | if (n, l) in memo: return memo[(n, l)] 8 | if n == 0: return [''] 9 | 10 | out = [] 11 | if l > 0: out.extend(')' + p for p in _generate_parentheses(n - 1, l - 1, memo)) 12 | if n > l: out.extend('(' + p for p in _generate_parentheses(n - 1, l + 1, memo)) 13 | 14 | memo[(n, l)] = out 15 | return out 16 | 17 | 18 | if __name__ == '__main__': 19 | n = 0 20 | expected = [''] 21 | actual = generate_parentheses(n) 22 | assert(expected == actual) 23 | 24 | n = 1 25 | expected = ['()'] 26 | actual = generate_parentheses(n) 27 | assert(expected == actual) 28 | 29 | n = 2 30 | expected = ['()()', '(())'] 31 | actual = generate_parentheses(n) 32 | assert(expected == actual) 33 | 34 | n = 3 35 | expected = ['()()()', '()(())', '(())()', '(()())', '((()))'] 36 | actual = generate_parentheses(n) 37 | assert(expected == actual) 38 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/longest_sum_subarray/python/kadane.py: -------------------------------------------------------------------------------- 1 | arr=list(map(int,input("enter the array of integers separated by space").split())) 2 | max_val=arr[0] 3 | global_val=arr[0] 4 | for i in range(1,len(arr)): 5 | max_val=max(arr[i],max_val+arr[i]) 6 | if max_val>global_val: 7 | global_val=max_val 8 | 9 | print("max sum subarray of a given array:{}".format(global_val)) 10 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/longest_sum_subarray/python/readme.md: -------------------------------------------------------------------------------- 1 | This is kadane algorithm which is intended to find out the max sum sub_array of a given array. -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/minimum_number_of_jumps/python/minjumps.py: -------------------------------------------------------------------------------- 1 | a=list(map(int,input("Enter The Array Separated by space that would indicate the maximum distance that can be covered from current position").split())) 2 | jmp=len(a)*[100] 3 | source=len(a)*[0] 4 | jmp[0]=0 5 | for i in range(0,len(a)-1): 6 | current=i 7 | for j in range(1,a[current]+1): 8 | if jjmp[current]+1 ): 10 | jmp[current+j]=jmp[current]+1 11 | source[current+j]=current 12 | 13 | print("Minimum Number Of Jumps Needed To Reach The Destination Is {}".format(jmp[len(a)-1])) 14 | 15 | print("The Number Of Jumps Required To Reach Corresponding Index Position:{}".format(jmp)) 16 | 17 | print("The Jump That Has Been Taken From Source Index To Reach Corresponding Index:{}".format(source)) 18 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/minimum_number_of_jumps/python/readme.md: -------------------------------------------------------------------------------- 1 | This Program is intended to find out the minimum number of jumps needed to reach the end of an array from the source(zeroth index). -------------------------------------------------------------------------------- /Algorithms/Dynamic Programming/rod_cutting_problem.py: -------------------------------------------------------------------------------- 1 | INT_MIN = -32767 2 | 3 | # Returns the best price for a rod of length n and prices of different pieces 4 | def cutRod(price, n): 5 | pro = [0 for x in range(n+1)] 6 | pro[0] = 0 7 | 8 | for i in range(1, n+1): 9 | max_pro = INT_MIN 10 | for j in range(i): 11 | max_pro = max(max_pro, price[j] + pro[i-j-1]) 12 | pro[i] = max_pro 13 | 14 | return pro[n] 15 | 16 | # Driver program 17 | if __name__ == '__main__': 18 | len_price = [1, 5, 8, 9, 10, 17, 17, 20] 19 | size = len(len_price) 20 | print("Maximum Obtainable Value is " + str(cutRod(len_price, size))) -------------------------------------------------------------------------------- /Algorithms/Greedy Algorithm/README.md: -------------------------------------------------------------------------------- 1 | like other algorithms greedy algorithm is an important topic from interview point of view 2 | -------------------------------------------------------------------------------- /Algorithms/Greedy Algorithm/Travelling_Salesman_Problem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define vr 4 4 | int TSP(int grph[][vr], int p) // implement traveling Salesman Problem. { 5 | vector ver; // 6 | for (int i = 0; i < vr; i++) 7 | if (i != p) 8 | ver.push_back(i); 9 | int m_p = INT_MAX; // store minimum weight of a graph 10 | do { 11 | int cur_pth = 0; 12 | int k = p; 13 | for (int i = 0; i < ver.size(); i++) { 14 | cur_pth += grph[k][ver[i]]; 15 | k = ver[i]; 16 | } 17 | cur_pth += grph[k][p]; 18 | m_p = min(m_p, cur_pth); // to update the value of minimum weight 19 | } 20 | while (next_permutation(ver.begin(), ver.end())); 21 | return m_p; 22 | } 23 | int main() { 24 | int grph[][vr] = { { 0, 5, 10, 15 }, //values of a graph in a form of matrix 25 | { 5, 0, 20, 30 }, 26 | { 10, 20, 0, 35 }, 27 | { 15, 30, 35, 0 } 28 | }; 29 | int p = 0; 30 | cout<< "\n The result is: "<< TSP(grph, p) << endl; 31 | return 0; 32 | } -------------------------------------------------------------------------------- /Algorithms/Kadane.cpp: -------------------------------------------------------------------------------- 1 | long long kadane(long long array[], int n) { 2 | long long max_so_far = INT_MIN, max_ending_here = 0; 3 | for (int i = 0; i < n; i++) 4 | { 5 | max_ending_here = max_ending_here + array[i]; 6 | if (max_so_far < max_ending_here) 7 | max_so_far = max_ending_here; 8 | 9 | if (max_ending_here < 0) 10 | max_ending_here = 0; 11 | } 12 | return max_so_far; 13 | } 14 | -------------------------------------------------------------------------------- /Algorithms/Maths/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Maths/Base Conversion/C/base_conversion.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | long long int to_decimal(long long int n, int b){ 5 | long long int dec = 0; 6 | long long int i = 1; 7 | while(n > 0){ 8 | dec += (n % 10) * i; 9 | i *= b; 10 | n /= 10; 11 | } 12 | return dec; 13 | } 14 | 15 | long long int to_base(long long int dec, int b){ 16 | long long int m = 0; 17 | long long int i = 1; 18 | while(dec > 0){ 19 | m += (dec % b) * i; 20 | i *= 10; 21 | dec /= b; 22 | } 23 | return m; 24 | } 25 | 26 | int main(){ 27 | long long int n; 28 | int x,y; 29 | printf("Enter number and base that it is in:\n"); 30 | scanf("%lld %d", &n, &x); 31 | printf("Enter base to convert to:\n"); 32 | scanf("%d", &y); 33 | printf("%lld \n", to_base(to_decimal(n, x), y)); 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Algorithms/Maths/Base Conversion/binary_number/check_multple_of3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int checking(char*,int); 6 | void main() 7 | { 8 | int b,i; 9 | char *a; 10 | a=(char*)calloc(b,sizeof(char)); 11 | printf("\nhow many digit binary you want to enter\n"); 12 | scanf("%d",&b); 13 | 14 | printf("\nenter the binary number"); 15 | fflush(stdin); 16 | gets(&a[0]); 17 | if(checking(a,b)) 18 | { 19 | printf("\nthe given binary number after converting into decimal is a multiple of 3"); 20 | } 21 | else 22 | printf("\nthe given binary number after converting into decimal is not a multiple of 3"); 23 | getch(); 24 | free(a); 25 | } 26 | int checking(char *a,int b) 27 | { 28 | int i,j=0,sum=0; 29 | 30 | for(i=b-1;i>=0;i--) 31 | { 32 | sum=sum+pow(2,j)*(int)*(a+i); 33 | j++; 34 | } 35 | return(sum%3==0); 36 | } 37 | -------------------------------------------------------------------------------- /Algorithms/Maths/Base Conversion/binary_number/readme.md: -------------------------------------------------------------------------------- 1 | This program ask the user to enter the number of dits in a binary number and then wants the the user to enter that number and then checks whether the entered binary number is a multiple of 3 or not. -------------------------------------------------------------------------------- /Algorithms/Maths/Catalan number/catalan_no.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | // A recursive function to find nth catalan number 6 | unsigned long int catalan(unsigned int n) 7 | { 8 | // Base case 9 | if (n <= 1) return 1; 10 | 11 | // catalan(n) is sum of catalan(i)*catalan(n-i-1) 12 | unsigned long int res = 0; 13 | for (int i=0; i 2 | using namespace std; 3 | int calcx(int n,int dv[], int rem[]){ 4 | int x=1; 5 | while(true){ 6 | int i=0; 7 | for(i=0; i>n; 23 | int dv[n],rem[n]; 24 | cout<<"\nEnter divisor array: "; 25 | for(int i=0; i>dv[i]; 27 | } 28 | cout<<"\nEnter remainder array: "; 29 | for(int i=0; i>rem[i]; 31 | } 32 | cout<<"\nThe value of x is "< 3 | 4 | // Function to return gcd of a and b 5 | int gcd(int a, int b) 6 | { 7 | if (a == 0) 8 | return b; 9 | return gcd(b%a, a); 10 | } 11 | 12 | // Driver program to test above function 13 | int main() 14 | { 15 | int a = 10, b = 15; 16 | printf("GCD(%d, %d) = %dn", a, b, gcd(a, b)); 17 | a = 35, b = 10; 18 | printf("GCD(%d, %d) = %dn", a, b, gcd(a, b)); 19 | a = 31, b = 2; 20 | printf("GCD(%d, %d) = %dn", a, b, gcd(a, b)); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/C/GCD.c: -------------------------------------------------------------------------------- 1 | #include 2 | int top=-1; 3 | int arr[20]; 4 | main() 5 | { 6 | signed int a,b,remain,max,min,s; 7 | printf("enter the two number whose gcd is to be found using euclid algorithm\n"); 8 | scanf("%d%d",&a,&b); 9 | if(a<0) 10 | a=-1*a; 11 | if(b<0) 12 | b=-1*b; 13 | max=(a>b)?a:b; 14 | min=(a0) 21 | { 22 | max=pop(); 23 | min=pop(); 24 | remain=max%min; 25 | s=max/min; 26 | printf("\n%d = %d *%d + %d",max,min,s,remain); 27 | stack(remain); 28 | stack(min); 29 | } 30 | printf("\ngcd of two function is %d",pop()); 31 | getch(); 32 | 33 | } 34 | void stack(int value) 35 | { 36 | top=top+1; 37 | arr[top]=value; 38 | } 39 | int pop() 40 | { 41 | int k=top; 42 | top--; 43 | return(arr[k]); 44 | } 45 | -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/C/readme.md: -------------------------------------------------------------------------------- 1 | GCD of two numbers is the largest number that divides both of them. A simple way to find GCD is to factorize both numbers and multiply common factors. 2 | 3 | ![GCD](https://www.geeksforgeeks.org/wp-content/uploads/GCD-1.jpg) 4 | # 5 | # Basic Euclidean Algorithm for GCD Here we used stack data structure and euclid algorithm to compute gcd 6 | The algorithm is based on below facts. 7 | 8 | 9 | 10 | ##Here euclidean formuala for calculation of gcd has been used.a=bq+r,where a is the largest number,b is the smallest number q is the quotient obtained by dividing a with b whereas r is the remainder ie a%b. 11 | ##in first step we calculate remainder(obtained by largest no%smallest no) and the quotient (obtained by doing largest no/smallest no )then we push remainder and smallest no in the stack. 12 | ##we carry out above steps in loop till the remaider becomes zero,in the beginning of the loop popping operation is performed at the end pushing is done. -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/CPP/euclidean_gcd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int gcd_util(int a, int b) 5 | { 6 | while (b) 7 | { 8 | int c = a; 9 | a = b; 10 | b = c % a; 11 | } 12 | return a; 13 | } 14 | 15 | int gcd(vector nos) 16 | { 17 | int result = nos[0]; 18 | for (auto i : nos) 19 | result = gcd_util(i, result); 20 | 21 | return result; 22 | } 23 | 24 | int main() 25 | { 26 | int n; 27 | vector nos; 28 | 29 | cout << "Enter number of inputs "; 30 | cin >> n; 31 | 32 | int i = 0; 33 | while (i++ < n) 34 | { 35 | int x; 36 | cout << "\nEnter " << i << " number "; 37 | cin >> x; 38 | nos.push_back(x); 39 | } 40 | 41 | cout << "GCD is " << gcd(nos); 42 | 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Euclidean GCD/CPP/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Euclidean GCD/Java/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/Python/euclidean_gcd.py: -------------------------------------------------------------------------------- 1 | def euclidean_gcd(a, b): 2 | while b: 3 | a, b = b, a % b 4 | return a 5 | 6 | 7 | def main(): 8 | print('GCD(1071, 462) = {}'.format(euclidean_gcd(1071, 462))); 9 | print('GCD(462, 1071) = {}'.format(euclidean_gcd(462, 1071))); 10 | print('GCD(60, 12) = {}'.format(euclidean_gcd(60, 12))); 11 | print('GCD(12, 60) = {}'.format(euclidean_gcd(12, 60))); 12 | print('GCD(50, 3) = {}'.format(euclidean_gcd(527, 23))); 13 | print('GCD(3, 50) = {}'.format(euclidean_gcd(23, 527))); 14 | print('GCD(100, 0) = {}'.format(euclidean_gcd(100, 0))); 15 | print('GCD(0, 100) = {}'.format(euclidean_gcd(0, 100))); 16 | print('GCD(8, 1) = {}'.format(euclidean_gcd(8, 1))); 17 | print('GCD(1, 8) = {}'.format(euclidean_gcd(1, 8))); 18 | print('GCD(1, 1) = {}'.format(euclidean_gcd(1, 1))); 19 | print('GCD(0, 0) = {}'.format(euclidean_gcd(0, 0))); 20 | 21 | 22 | if __name__ == '__main__': 23 | main() 24 | -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Euclidean GCD/Python/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Euclidean GCD/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Euclidean GCD/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Factorial/Java/Factorial.java: -------------------------------------------------------------------------------- 1 | public class Factorial { 2 | 3 | static int factorialIterative(int num) { 4 | if (num <= 1) return 1; 5 | 6 | int total = 1; 7 | 8 | for (int i = 1; i < num + 1; i++) { 9 | total *= i; 10 | } 11 | 12 | return total; 13 | } 14 | 15 | static int factorialRecursive(int num) { 16 | if (num <= 1) return 1; 17 | 18 | return num * factorialRecursive(num - 1); 19 | } 20 | 21 | public static void main(String[] args) { 22 | System.out.println(factorialIterative(5)); 23 | System.out.println(factorialRecursive(5)); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Algorithms/Maths/Factorial/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Factorial/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Factorial/cpp/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int i,fact=1,number; 6 | cout<<"Enter any Number: "; 7 | cin>>number; 8 | 9 | for(i=1;i<=number;i++){ 10 | fact=fact*i; 11 | } 12 | 13 | cout<<"Factorial of " < 2 | int main() 3 | { 4 | int count, first_term = 0, second_term = 1, next_term, i; 5 | 6 | //Ask user to input number of terms 7 | printf("Enter the number of terms:\n"); 8 | scanf("%d",&count); 9 | 10 | printf("First %d terms of Fibonacci series:\n",count); 11 | for ( i = 0 ; i < count ; i++ ) 12 | { 13 | if ( i <= 1 ) 14 | next_term = i; 15 | else 16 | { 17 | next_term = first_term + second_term; 18 | first_term = second_term; 19 | second_term = next_term; 20 | } 21 | printf("%d\n",next_term); 22 | } 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/C/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Fibonacci series/C/a.out -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/C/mycode.c: -------------------------------------------------------------------------------- 1 | // Author: Amar Gwari Date: 07/10/19 Time: 00:49 2 | // this program will show the first 'n' elements of the fibonacci sequence 3 | #include 4 | int main() 5 | { 6 | long long int first = 0, second = 1, next = 0, n,i; 7 | printf("Enter the number of elements you wanna see:\n"); 8 | scanf("%lld", &n); 9 | printf("\n"); 10 | //now 'n' is known (^o^), now writing code to actually find fibonacci sequence... 11 | if(i == 0) 12 | printf("0\n"); 13 | if(i>=0) 14 | { printf("1 "); 15 | for(i=1;i.<)/ 24 | return 0; 25 | } 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/C/n_terms_fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | int fibonacci(int n) 3 | { 4 | if (n==1) 5 | return 1; 6 | if (n==2) 7 | return 1; 8 | return fibonacci(n-1) + fibonacci(n-2); 9 | } 10 | int main(void) 11 | { 12 | int n; 13 | printf("enter the number of terms of the fibonacci series to be printed: "); 14 | scanf("%d",&n); 15 | for (int i=1;i<=n;i++) 16 | printf("%d ",fibonacci(i)); 17 | } 18 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Fibonacci series/C/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/CPP/Fibonacci_DP.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Fibonacci Dynamic Programming approach 5 | int fib(int n){ 6 | int f[n+1]; 7 | f[0] = 0, f[1] = 1; 8 | for(int i = 2; i <= n; i++){ 9 | f[i] = f[i-1] + f[i-2]; 10 | } 11 | return f[n]; 12 | } 13 | 14 | // Main Fnnction 15 | int main(){ 16 | int N; 17 | cout << "Enter the number:"; 18 | cin >> N; 19 | cout << "Fibonacci number is: "; 20 | cout << fib(N) << endl; 21 | return 0; 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/CPP/fibonacci_series.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | vector fibonacci(int n) 5 | { 6 | vector fib{0, 1}; 7 | 8 | for (int i = 2; i < n; i++) 9 | fib.push_back(fib[i - 1] + fib[i - 2]); 10 | 11 | return fib; 12 | } 13 | 14 | int main() 15 | { 16 | int n; 17 | cout << "Enter the number of terms in fibonacci series "; 18 | cin >> n; 19 | 20 | cout << "Fibonacci Series is "; 21 | 22 | if (n == 1) 23 | cout << n; 24 | else if (n == 2) 25 | cout << n - 2 << " " << n - 1; 26 | else 27 | { 28 | vector fibo_series = fibonacci(n); 29 | 30 | for (auto i : fibo_series) 31 | cout << i << " "; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/CPP/readme.md: -------------------------------------------------------------------------------- 1 | # Fibonacci Seris:- 2 | - This is DP approach of fibonacci Series in C++ 3 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/Java/Fibonacci.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Fibonacci { 3 | public static void main (String args[]) { 4 | int count, firstValue = 0, secondValue = 1, nextValue; 5 | Scanner sc = new Scanner(System.in); 6 | 7 | // Input number of terms from user 8 | System.out.println("Enter the number of terms:\n"); 9 | count = sc.nextInt(); 10 | System.out.println(firstValue); 11 | System.out.println(secondValue); 12 | 13 | for ( int i = 2 ; i < count ; i++ ) 14 | { 15 | nextValue = firstValue + secondValue; 16 | firstValue = secondValue; 17 | secondValue = nextValue; 18 | System.out.println(nextValue); 19 | } 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Fibonacci series/Java/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/Python/Fibonacci_Sequence.py: -------------------------------------------------------------------------------- 1 | # Fibonacci Sequence 2 | 3 | if __name__ == '__main__': 4 | f = [0, 1] 5 | index1=0 6 | index2=1 7 | fibonacci_len = 10 # Lenght of Fibonacci Sequence 8 | for n in range(fibonacci_len): 9 | val = f[index1+n]+f[index2+n] 10 | f.append(val) 11 | f.pop(0) 12 | print f 13 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/Python/Fibonnacci.py: -------------------------------------------------------------------------------- 1 | #Implementation of fibonacci in python 2 | # Fibonnaci with first value 0 i.e. 1:0 3 | 4 | class Fibonacci: 5 | def __init__(self,store={1:0,2:1}): 6 | self.dict=store 7 | 8 | def Fibonacci_series(self,number): 9 | series=[] 10 | for i in range(1,number+1): 11 | series.append(self.Fibonacci_number(i)) 12 | return series 13 | 14 | def Fibonacci_number(self,number): 15 | if number in self.dict: 16 | return self.dict[number] 17 | else: 18 | k=self.Fibonacci_number(number-1)+self.Fibonacci_number(number-2) 19 | self.dict[number]=k 20 | return k 21 | 22 | def main(): 23 | fibo=Fibonacci() 24 | print(fibo.Fibonacci_number(500)) 25 | print(fibo.Fibonacci_series(50)) 26 | 27 | if __name__ == "__main__": 28 | main() 29 | 30 | -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Fibonacci series/Python/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Fibonacci series/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Fibonacci series/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Magic Number/Magic Number.py: -------------------------------------------------------------------------------- 1 | input_num = int(input()) 2 | 3 | def isMagic(input_num): 4 | z = len(list(str(input_num))) 5 | for x in range(1,z+1): 6 | rem = int(input_num % 10) 7 | input_num = int(input_num/10) 8 | input_num = rem + input_num 9 | if(input_num == 1): 10 | print('Magic Number') 11 | else: 12 | print("Not a Magic Number") 13 | 14 | 15 | isMagic(input_num) 16 | 17 | -------------------------------------------------------------------------------- /Algorithms/Maths/Magic Number/MagicNo.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | num = int(input("Enter a Number \n")) 4 | digitCount = int(math.log10(num))+1 5 | sumOfDigits = 0 6 | 7 | temp = num #copying num 8 | 9 | #calculating sum of digits of temp(i.e num) until 10 | #sumOfDigits is a single digit 11 | while( digitCount > 1): 12 | 13 | sumOfDigits = 0 14 | 15 | while(temp > 0): 16 | sumOfDigits += temp%10 17 | temp = temp//10 18 | 19 | temp = sumOfDigits 20 | #count the digits of sumOfDigits 21 | digitCount = int(math.log10(sumOfDigits))+1 22 | 23 | 24 | #check whether sumOfDigits == 1 25 | if(sumOfDigits == 1): 26 | print("Magic number") 27 | else: 28 | print("Not a magic number") 29 | 30 | -------------------------------------------------------------------------------- /Algorithms/Maths/Magic Number/MagicNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | class MagicNumber 4 | { 5 | public static void isMagicNumber(int n) 6 | { 7 | int sum = 0; 8 | while (n > 0 || sum > 9) 9 | { 10 | if (n == 0) 11 | { 12 | n = sum; 13 | sum = 0; 14 | } 15 | sum += n % 10; 16 | n /= 10; 17 | } 18 | 19 | if (sum == 1) 20 | System.out.println("Magic Number!"); 21 | else 22 | System.out.println("Not a Magic Number!"); 23 | } 24 | 25 | public static void main(String args[]) { 26 | 27 | Scanner read = new Scanner(System.in); 28 | System.out.print("Enter a number: "); 29 | int n = read.nextInt(); 30 | isMagicNumber(n); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Algorithms/Maths/Magic Number/Nodejs/MagicNumber.js: -------------------------------------------------------------------------------- 1 | 2 | const readline = require("readline"); 3 | 4 | const rl = readline.createInterface({ 5 | input: process.stdin, 6 | output: process.stdout 7 | }); 8 | 9 | rl.question("Enter the number: ", a => { 10 | var n=parseInt(a) 11 | var length= a.length; 12 | while(length>1){ 13 | var arr = n.toString(10).replace(/\D/g, '0').split('').map(Number); 14 | 15 | 16 | n = arr.reduce(myFunc); 17 | length=n.toString().length; 18 | } 19 | if(n==1) 20 | console.log("The number is a magic number"); 21 | else 22 | console.log("The number is not a magic number"); 23 | process.exit(); 24 | }); 25 | 26 | 27 | function myFunc(total, num) { 28 | return total + num; 29 | } -------------------------------------------------------------------------------- /Algorithms/Maths/Magic Number/magic_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void is_magic_number(int n) 4 | { 5 | int sum = 0; 6 | 7 | // The loop stops only when n becomes 0 8 | // and sum is a single digit number. 9 | while (n > 0 || sum > 9) 10 | { 11 | if (n == 0) { 12 | n = sum; 13 | sum = 0; 14 | } 15 | sum += n % 10; 16 | n /= 10; 17 | } 18 | 19 | if (sum == 1) 20 | printf("Magic Number!\n"); 21 | else 22 | printf("Not a Magic Number!\n"); 23 | } 24 | 25 | int main() { 26 | 27 | int n; 28 | printf("Enter a number: "); 29 | scanf("%d", &n); 30 | is_magic_number(n); 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /Algorithms/Maths/Magic Number/magic_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void is_magic_number(int n) 5 | { 6 | int sum = 0; 7 | 8 | // The loop stops only when n becomes 0 9 | // and sum is a single digit number. 10 | while (n > 0 || sum > 9) 11 | { 12 | if (n == 0) { 13 | n = sum; 14 | sum = 0; 15 | } 16 | sum += n % 10; 17 | n /= 10; 18 | } 19 | 20 | if (sum == 1) 21 | cout << "Magic Number!" << endl; 22 | else 23 | cout << "Not a Magic Number!" << endl; 24 | } 25 | 26 | int main() { 27 | 28 | int n; 29 | cout << "Enter a number: "; 30 | cin >> n; 31 | is_magic_number(n); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Algorithms/Maths/Modular Exponentiation/C/ModularExponentiation.c: -------------------------------------------------------------------------------- 1 | // Iterative C program to compute modular power 2 | #include 3 | 4 | /* Iterative Function to calculate (x^y)%p in O(log y) */ 5 | int power(int x, unsigned int y, int p) 6 | { 7 | int res = 1; // Initialize result 8 | 9 | x = x % p; // Update x if it is more than or 10 | // equal to p 11 | 12 | while (y > 0) 13 | { 14 | // If y is odd, multiply x with result 15 | if (y & 1) 16 | res = (res*x) % p; 17 | 18 | // y must be even now 19 | y = y>>1; // y = y/2 20 | x = (x*x) % p; 21 | } 22 | return res; 23 | } 24 | 25 | // Driver program to test above functions 26 | int main() 27 | { 28 | int x = 2; 29 | int y = 5; 30 | int p = 13; 31 | printf("Power is %u", power(x, y, p)); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Algorithms/Maths/Modular Exponentiation/C/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Modular Exponentiation/C/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Modular Exponentiation/CPP/ModularExponentiation.cpp: -------------------------------------------------------------------------------- 1 | // Iterative C program to compute modular power 2 | #include 3 | 4 | /* Iterative Function to calculate (x^y)%p in O(log y) */ 5 | int power(int x, unsigned int y, int p) 6 | { 7 | int res = 1; // Initialize result 8 | 9 | x = x % p; // Update x if it is more than or 10 | // equal to p 11 | 12 | while (y > 0) 13 | { 14 | // If y is odd, multiply x with result 15 | if (y & 1) 16 | res = (res*x) % p; 17 | 18 | // y must be even now 19 | y = y>>1; // y = y/2 20 | x = (x*x) % p; 21 | } 22 | return res; 23 | } 24 | 25 | // Driver program to test above functions 26 | int main() 27 | { 28 | int x = 2; 29 | int y = 5; 30 | int p = 13; 31 | printf("Power is %u", power(x, y, p)); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Algorithms/Maths/Modular Exponentiation/Java/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Modular Exponentiation/Java/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Modular Exponentiation/Python/ModularExponentiation.py: -------------------------------------------------------------------------------- 1 | # Iterative Python3 program 2 | # to compute modular power 3 | 4 | # Iterative Function to calculate 5 | # (x^y)%p in O(log y) 6 | def power(x, y, p) : 7 | res = 1 # Initialize result 8 | 9 | # Update x if it is more 10 | # than or equal to p 11 | x = x % p 12 | 13 | while (y > 0) : 14 | 15 | # If y is odd, multiply 16 | # x with result 17 | if ((y & 1) == 1) : 18 | res = (res * x) % p 19 | 20 | # y must be even now 21 | y = y >> 1 # y = y/2 22 | x = (x * x) % p 23 | 24 | return res 25 | 26 | 27 | # Driver Code 28 | 29 | x = 2; y = 5; p = 13 30 | print("Power is ", power(x, y, p)) 31 | -------------------------------------------------------------------------------- /Algorithms/Maths/Modular Exponentiation/Python/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Modular Exponentiation/Python/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/C/Palindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, reverse = 0, t; 6 | 7 | printf("Enter a number to check if it is a palindrome or not\n"); 8 | scanf("%d", &n); 9 | 10 | t = n; 11 | 12 | while (t != 0) 13 | { 14 | reverse = reverse * 10; 15 | reverse = reverse + t%10; 16 | t = t/10; 17 | } 18 | 19 | if (n == reverse) 20 | printf("%d is a palindrome number.\n", n); 21 | else 22 | printf("%d isn't a palindrome number.\n", n); 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Pallindrome number/C/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/CPP/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | bool palindrome(int x) 4 | { 5 | int n=x;//n acts as temporary variable for storing x 6 | int sum=0;//sum stores the inverted number 7 | while(n>0) 8 | { 9 | sum=sum*10+n%10; 10 | n/=10; 11 | } 12 | return sum==x?1:0; 13 | } 14 | int main() 15 | { 16 | cout<0){ 9 | r=n%10; 10 | sum=(sum*10)+r; 11 | n=n/10; 12 | } 13 | if(temp==sum) 14 | System.out.println("palindrome number "); 15 | else 16 | System.out.println("not palindrome"); 17 | } 18 | } -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/Java/Pallindrome_number.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class Pallindrome_number 4 | { 5 | public static void main(String[] args) { 6 | 7 | System.out.println("input a number:"); 8 | 9 | Scanner read = new Scanner(System.in); 10 | String in = read.nextLine(); 11 | 12 | int num= Integer.parseInt(in); 13 | int newNum=0; 14 | int temp = num; 15 | 16 | 17 | while(num!=0) { 18 | newNum= newNum *10 + num%10; 19 | num /= 10; 20 | } 21 | if(temp == newNum) 22 | System.out.println("it is a pallindrome number"); 23 | else 24 | System.out.println("it is NOT a pallindrome number"); 25 | } 26 | } -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/Java/Pallindrome_string.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Pallindrome_string{ 3 | public static void pallindrome(String word){ 4 | word = word.toLowerCase(); 5 | word = word.replace(" ",""); 6 | 7 | int c=0,x=word.length(); 8 | for(int i=0;i0): 5 | dig=n%10 6 | rev=rev*10+dig 7 | n=n//10 8 | if(temp==rev): 9 | print("The number is a palindrome!") 10 | else: 11 | print("The number isn't a palindrome!") -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/Python/Pallindrome_number.py: -------------------------------------------------------------------------------- 1 | #CREATED BY Ankur Pandey (Github : AnkDos) 2 | 3 | def check_pallindrome(number_to_check): 4 | return str(number_to_check)[::-1] == str(number_to_check) #AS This Solution will raise TypeError with int 5 | 6 | print(check_pallindrome(1991)) #returns true if pallindrome else false 7 | -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Pallindrome number/Python/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Pallindrome number/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Pallindrome number/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Perfect Number/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/C/PerfectNumber.c: -------------------------------------------------------------------------------- 1 | /* C Program to Find Perfect Number in a given interval eg. 1 to 1000 */ 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int Number, Sum, i, Minimum, Maximum; 8 | 9 | printf("\n Please Enter the Minimum & Maximum Values\n"); 10 | scanf("%d %d", &Minimum, &Maximum); 11 | 12 | printf("Perfect Numbers Between %d and %d are:\n", Minimum, Maximum); 13 | for(Number=Minimum; Number<=Maximum; Number++) 14 | { 15 | for(i = 1, Sum =0 ; i < Number ; i++) 16 | { 17 | if(Number % i == 0) 18 | Sum = Sum + i ; 19 | } 20 | 21 | if (Sum == Number) 22 | printf(" %d ", Number) ; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Perfect Number/C/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/CPP/perfectnumber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int is_perfect_num(int num) 5 | { 6 | int temp = num; 7 | int sum = 0; 8 | while(num >0) 9 | { 10 | int r = num /10; 11 | sum = sum + (r*r); 12 | 13 | } 14 | if(sum == temp) 15 | return 1; 16 | else 17 | return 0; 18 | 19 | } 20 | 21 | void main(){ 22 | clrscr(); 23 | int n; 24 | cout<<"Enter a number"; 25 | cin>>n; 26 | int res = is_perfect_num(n); 27 | if(res == 1) 28 | cout<<"Perfect number"; 29 | else 30 | cout<<"Not a perfect number" 31 | getch(); 32 | } -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Perfect Number/CPP/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Perfect Number/Java/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/Python/Perfect_Number.py: -------------------------------------------------------------------------------- 1 | # Python Program to find Perfect Number using For loop 2 | 3 | Number = int(input(" Please Enter any Number: ")) 4 | Sum = 0 5 | for i in range(1, Number): 6 | if(Number % i == 0): 7 | Sum = Sum + i 8 | if (Sum == Number): 9 | print(" %d is a Perfect Number" %Number) 10 | else: 11 | print(" %d is not a Perfect Number" %Number) 12 | -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/Python/perfect.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | print( "Enter Perfect Number interval:" ) 3 | 4 | start = int(input("Start:")) 5 | end = int(input("End:")) 6 | 7 | for number in range(start, end): 8 | accum = 0 9 | 10 | for index in range(1 , number): 11 | if number % index == 0: 12 | accum = accum + index 13 | 14 | if accum == number: 15 | print(number) 16 | 17 | if __name__ == '__main__': 18 | main() 19 | -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Perfect Number/Python/readme.md -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Perfect Number/README.md -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Maths/Perfect Number/a.out -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/perfect number.c: -------------------------------------------------------------------------------- 1 | //Author: Amar Gwari Date: 06/10/19 Time: 20:08 2 | #include 3 | int main() 4 | { 5 | long long int N,i=0,a=0,b,z; 6 | printf("Please Enter The Number Of Your Choice\n"); 7 | scanf("%lld",&N); 8 | for(i=1;i<=N/2;i++) 9 | { 10 | if(N%i == 0) 11 | { 12 | a+=i; 13 | } 14 | } 15 | 16 | if(a == N) 17 | printf("\nThe Number Is Perfect!\n"); 18 | else 19 | printf("\nThe Number Is Not Perfect\n"); 20 | return 0; 21 | } 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/perfect_num.cpp: -------------------------------------------------------------------------------- 1 | **Description**: To find all perfect numbers till 10000 2 | 3 | #include 4 | using namespace std; 5 | 6 | // Returns true if n is perfect 7 | bool isPerfect(long long int n) 8 | { 9 | // To store sum of divisors 10 | long long int sum = 1; 11 | 12 | // Find all divisors and add them 13 | for (long long int i=2; i*i<=n; i++) 14 | { 15 | if (n%i==0) 16 | { 17 | if(i*i!=n) 18 | sum = sum + i + n/i; 19 | else 20 | sum=sum+i; 21 | } 22 | } 23 | // If sum of divisors is equal to 24 | // n, then n is a perfect number 25 | if (sum == n && n != 1) 26 | return true; 27 | 28 | return false; 29 | } 30 | 31 | // Driver program 32 | int main() 33 | { 34 | cout << "Below are all perfect numbers till 10000\n"; 35 | for (int n =2; n<10000; n++) 36 | if (isPerfect(n)) 37 | cout << n << " is a perfect number\n"; 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect Number/perfectno.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main(){ 5 | char string1[20]; 6 | int i, length; 7 | int flag = 0; 8 | 9 | cout << "Enter a string: "; cin >> string1; 10 | 11 | length = strlen(string1); 12 | 13 | for(i=0;i < length ;i++){ 14 | if(string1[i] != string1[length-i-1]){ 15 | flag = 1; 16 | break; 17 | } 18 | } 19 | 20 | if (flag) { 21 | cout << string1 << " is not a palindrome" << endl; 22 | } 23 | else { 24 | cout << string1 << " is a palindrome" << endl; 25 | } 26 | system("pause"); 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect number/C/PerfectNumber.c: -------------------------------------------------------------------------------- 1 | /* C Program to Find Perfect Number in a given interval eg. 1 to 1000 */ 2 | 3 | #include 4 | 5 | int main() 6 | { 7 | int Number, Sum, i, Minimum, Maximum; 8 | 9 | printf("\n Please Enter the Minimum & Maximum Values\n"); 10 | scanf("%d %d", &Minimum, &Maximum); 11 | 12 | printf("Perfect Numbers Between %d and %d are:\n", Minimum, Maximum); 13 | for(Number=Minimum; Number<=Maximum; Number++) 14 | { 15 | for(i = 1, Sum =0 ; i < Number ; i++) 16 | { 17 | if(Number % i == 0) 18 | Sum = Sum + i ; 19 | } 20 | 21 | if (Sum == Number) 22 | printf(" %d ", Number) ; 23 | } 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Algorithms/Maths/Perfect number/C/perfect_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int n,i=1,sum=0; 4 | 5 | printf("Enter a number: "); 6 | scanf("%d",&n); 7 | 8 | while(i 2 | 3 | using namespace std; 4 | 5 | bool IsPrime[10000001]; 6 | void sieve_erathostenes(){ 7 | memset(IsPrime,true,sizeof IsPrime); 8 | IsPrime[1]=false; 9 | long i=2,j; 10 | while(i<=10000){ 11 | j=2; 12 | if(IsPrime[i]){ 13 | while(i*j<=10000000){ 14 | IsPrime[i*j]=false; 15 | j++; 16 | } 17 | } 18 | i++; 19 | } 20 | } 21 | 22 | int main(){ 23 | int val; 24 | sieve_erathostenes(); 25 | 26 | cin >> val; 27 | cout << ((IsPrime[val])?"Prime":"Not Prime")< 2 | using namespace std; 3 | 4 | void SieveOfEratosthenes(int n) 5 | { 6 | bool prime[n+1]; 7 | memset(prime, true, sizeof(prime)); 8 | 9 | for (int p=2; p*p<=n; p++) 10 | { 11 | 12 | if (prime[p] == true) 13 | { 14 | 15 | for (int i=p*p; i<=n; i += p) 16 | prime[i] = false; 17 | } 18 | } 19 | 20 | 21 | for (int p=2; p<=n; p++) 22 | if (prime[p]) 23 | cout << p << " "; 24 | } 25 | 26 | int main() 27 | { 28 | int n = 30; 29 | cout << "Following are the prime numbers smaller " 30 | << " than or equal to " << n << endl; 31 | SieveOfEratosthenes(n); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Algorithms/Maths/Sieve of Eratosthenes algorithm/sieve.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | typedef enum Boolean {FALSE = 0, TRUE = 1} Boolean; 5 | 6 | int main (int argc, char **argv) 7 | { 8 | int N = 0, i = 0, j = 0; 9 | int* numbers = NULL; 10 | Boolean *sieve; 11 | N = strtol(argv[1], NULL, 10); 12 | 13 | if (N < 2) printf("\n No prime numbers \n\n"); 14 | else 15 | { 16 | sieve = calloc(N -1, sizeof(Boolean)); 17 | numbers = malloc( (N -1)*sizeof(int) ); 18 | 19 | for (i=2; i<=N; i++) 20 | numbers[i-2] = i; 21 | 22 | for( i=0; i <= (N/2); i++ ) 23 | for(j=i+1; j<=N -2; j++) 24 | if( (numbers[j] % numbers[i]) == 0 ) 25 | sieve[j] = TRUE; 26 | 27 | for(i=0; i 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int n,r,sum=0,temp; 8 | cout<<"Enter the Number= "; 9 | cin>>n; 10 | temp=n; 11 | 12 | while(n>0) 13 | { 14 | r=n%10; 15 | sum=sum+(r*r*r); 16 | n=n/10; 17 | } 18 | 19 | if(temp==sum) 20 | cout<<"Armstrong Number."< 0: 7 | digit = temp % 10 8 | sum += digit ** 3 9 | temp //= 10 10 | # display the result 11 | if num == sum: 12 | print(num,"is an Armstrong number") 13 | else: 14 | print(num,"is not an Armstrong number") -------------------------------------------------------------------------------- /Algorithms/Maths/factorial/factorial.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int n,a[200]={0},s=0,j; 6 | cin>>n; 7 | a[0]=1; 8 | for(int i=1;i<=n;i++) 9 | { 10 | j=0; 11 | int carry=0; 12 | while(carry>0||a[j]>0||j<=s) 13 | { 14 | 15 | a[j] = a[j]*i; 16 | a[j]+=carry; 17 | carry=a[j]/10; 18 | a[j]=a[j]%10; 19 | j++; 20 | } 21 | a[j]+=carry; 22 | if(a[j]==0) 23 | j--; 24 | if(j>s) 25 | s=j; 26 | } 27 | for(int i=j;i>=0;i--) 28 | cout< 3 | using namespace std; 4 | 5 | // Function to print the first n pure numbers 6 | void nPureNumbers(int n) 7 | { 8 | 9 | queue q; 10 | vector ans; 11 | 12 | // Push the starting two elements 13 | q.push("44"); 14 | q.push("55"); 15 | int total = 2; 16 | 17 | // While generated numbers are less than n 18 | while (ans.size() < n) { 19 | 20 | string temp = q.front(); 21 | q.pop(); 22 | ans.push_back(temp); 23 | 24 | q.push("4" + temp + "4"); 25 | q.push("5" + temp + "5"); 26 | } 27 | 28 | // Sorting strings based on their value 29 | sort(ans.begin(), ans.end(), [](auto s, auto s2) { 30 | if (s.size() == s2.size()) 31 | return s < s2; 32 | else 33 | return s.size() < s2.size(); 34 | }); 35 | 36 | // Print first n pure numbers 37 | for (auto i : ans) { 38 | cout << i << " "; 39 | } 40 | } 41 | 42 | // Driver code 43 | int main() 44 | { 45 | int n = 4; 46 | 47 | nPureNumbers(n); 48 | 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /Algorithms/Recursion/palindrome/palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | int rev(int n, int temp) 6 | { 7 | 8 | if (n == 0) 9 | return temp; 10 | 11 | // stores the reverse of a number 12 | temp = (temp * 10) + (n % 10); 13 | return rev(n / 10, temp); 14 | } 15 | 16 | 17 | int main() 18 | { 19 | 20 | cout<<"Enter the Number= "; 21 | cin>>n; 22 | int temp = rev(n, 0); 23 | if (temp == n) 24 | cout << "yes" << endl; 25 | else 26 | cout << "no" << endl; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Algorithms/Recursion/palindrome/palindrome.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | class Palindrome 4 | { 5 | 6 | static int rev(int n, int temp) 7 | { 8 | if (n == 0) 9 | return temp; 10 | 11 | // stores the reverse of a number 12 | temp = (temp * 10) + (n % 10); 13 | return rev(n / 10, temp); 14 | } 15 | 16 | 17 | public static void main (String[] args) 18 | { 19 | int n = 101; 20 | int temp = rev(n, 0); 21 | 22 | if (temp == n) 23 | System.out.println("yes"); 24 | else 25 | System.out.println("no" ); 26 | } 27 | 28 | 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Algorithms/Recursion/palindrome/palindrome.py: -------------------------------------------------------------------------------- 1 | def rev(n, temp): 2 | if (n == 0): 3 | return temp; 4 | 5 | # stores the reverse of a number 6 | temp = (temp * 10) + (n % 10); 7 | 8 | return rev(n / 10, temp); 9 | 10 | 11 | 12 | n = int(input("enter a number : ")); 13 | temp = rev(n, 0); 14 | if (temp != n): 15 | print("yes"); 16 | else: 17 | print("no"); 18 | 19 | -------------------------------------------------------------------------------- /Algorithms/Recursion/tower_of_hanoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void tower_of_hanoi(int n, char from, char to, char temp) { 5 | if(n == 1) { 6 | printf("Move Disc 1: %c -> %c\n", from, to); 7 | return; 8 | } 9 | 10 | tower_of_hanoi(n-1, from, temp, to); 11 | printf("Move Disc %d: %c -> %c\n", n, from , to); 12 | tower_of_hanoi(n-1, temp, to , from); 13 | } 14 | 15 | int main() { 16 | int n; 17 | scanf("%d", &n); 18 | tower_of_hanoi(n, 'A', 'C', 'B'); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Binary Search/C/binary_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | 6 | void binary(int * arr, int b, int n , int find) 7 | { 8 | 9 | if( n>=b ) 10 | { 11 | int mid = (b+n)/2 ; 12 | if(arr[mid] == find)printf("\n\nELement found at %d ",mid); 13 | 14 | 15 | if (arr[mid] 4 | #include 5 | 6 | void main() 7 | { 8 | int n, arr[50], first, mid, last, key, loc, i; 9 | int flag=0; 10 | clrscr(); 11 | 12 | printf("\nEnter number of elements: "); 13 | scanf("%d", &n); 14 | printf("\nEnter the elements: "); 15 | 16 | for(i=0; iarr[mid]) 33 | first=mid+1; 34 | else 35 | last=mid-1; 36 | } 37 | 38 | if(flag==0) 39 | printf("\nElement not found"); 40 | getch(); 41 | 42 | } -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Binary Search/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Binary Search/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Binary Search/Ruby/binary_search.rb: -------------------------------------------------------------------------------- 1 | #Created By Ankur Pandey (Github : AnkDos) 2 | 3 | def binary_search (target,ar) 4 | begins = 0 ; ends = ar.length-1 5 | not_found = true 6 | while begins <= ends 7 | mid = (begins + ends)/2 8 | if target > ar[mid] 9 | begins = mid + 1 10 | elsif target < ar[mid] 11 | ends = mid - 1 12 | elsif target == ar[mid] 13 | not_found = false 14 | return "Found at index #{mid}" 15 | break 16 | end 17 | end 18 | return "Doesn't Exists" if not_found == true 19 | end 20 | 21 | ar = [1,2,3,8,31,32,68,78,213,224,564,3211,24453,78674] 22 | print binary_search(564,ar) 23 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Binary Search/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Binary Search/a.out -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Binary Search/binary_Search_Iterative.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Binary Search algorithms - Iterative 5 | int binary_search_iterative(int *array, int l, int r, int key){ 6 | while(l<=r){ 7 | int mid = l + (r - l)/2; // ALT:- int mid = ((unsigned int)l + (unsigned int)r) >> 1; (don't fail in overflow like (l+r)/2 ) 8 | if(key == array[mid]) 9 | return mid; 10 | else if(key < array[mid]) 11 | r = mid - 1; 12 | else 13 | l = mid + 1; 14 | } 15 | return -1; 16 | } 17 | 18 | int main(int argc, char const *argv[]){ 19 | int N, target; 20 | cout << "Enter the size of array:"; 21 | cin >> N; 22 | cout << "Enter the taget element to be search:"; 23 | cin >> target; 24 | int A[N]; 25 | cout << "Enter the array elements:"; 26 | for(int i = 0; i < N; i++) cin >> A[i]; 27 | int pos = binary_search_iterative(A, 0, N-1, target); 28 | cout << "index of target " << target << " is: " << pos << endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Binary Search/binary_search.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Scanner; 3 | 4 | public class BinarySearch { 5 | public static void main(String[] args) { 6 | 7 | int[] arr = {3,6,8,12,18}; 8 | Scanner scanner = new Scanner(System.in); 9 | System.out.println("enter no to search"); 10 | int n = scanner.nextInt(); 11 | Arrays.sort(arr); 12 | System.out.println(binarySearch(arr, 0, arr.length - 1, n)); 13 | 14 | } 15 | 16 | private static int binarySearch(int[] arr, int lo, int hi, int item) { 17 | 18 | int mid = (lo + hi) / 2; 19 | if (item > arr[mid]) { 20 | lo = mid + 1; 21 | return binarySearch(arr, lo, hi, item); 22 | } else if (item >= arr[mid]) { 23 | return mid; 24 | } else if (item < arr[mid]) { 25 | hi = mid -1; 26 | return binarySearch(arr, lo, hi, item); 27 | } else 28 | return -1; 29 | 30 | } 31 | } -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Binary Search/binary_search_iter.c: -------------------------------------------------------------------------------- 1 | //Binary Search Iterative Method 2 | 3 | #include 4 | #include 5 | 6 | void main() 7 | { 8 | int n, arr[50], first, mid, last, key, loc, i; 9 | int flag=0; 10 | clrscr(); 11 | 12 | printf("\nEnter number of elements: "); 13 | scanf("%d", &n); 14 | printf("\nEnter the elements: "); 15 | 16 | for(i=0; iarr[mid]) 33 | first=mid+1; 34 | else 35 | last=mid-1; 36 | } 37 | 38 | if(flag==0) 39 | printf("\nElement not found"); 40 | getch(); 41 | 42 | } -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bogo Sort/bogo.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Bogo Sort 2 | import random 3 | 4 | # Sorts array a[0..n-1] using Bogo sort 5 | def bogoSort(a): 6 | n = len(a) 7 | while (is_sorted(a)== False): 8 | shuffle(a) 9 | 10 | # To check if array is sorted or not 11 | def is_sorted(a): 12 | n = len(a) 13 | for i in range(0, n-1): 14 | if (a[i] > a[i+1] ): 15 | return False 16 | return True 17 | 18 | # To generate permuatation of the array 19 | def shuffle(a): 20 | n = len(a) 21 | for i in range (0,n): 22 | r = random.randint(0,n-1) 23 | a[i], a[r] = a[r], a[i] 24 | 25 | # Driver code to test above 26 | a = [3, 2, 4, 1, 0, 5] 27 | bogoSort(a) 28 | print("Sorted array :") 29 | for i in range(len(a)): 30 | print ("%d" %a[i]), 31 | 32 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bogo Sort/bogosort.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | #main function 4 | def bogoSort(a): 5 | n = len(a) 6 | while (is_sorted(a)== False): 7 | shuffle(a) 8 | 9 | #if sorted 10 | def is_sorted(a): 11 | n = len(a) 12 | for i in range(0, n-1): 13 | if (a[i] > a[i+1] ): 14 | return False 15 | return True 16 | 17 | #random shit 18 | def shuffle(a): 19 | n = len(a) 20 | for i in range (0,n): 21 | r = random.randint(0,n-1) 22 | a[i], a[r] = a[r], a[i] 23 | 24 | a = [3, 2, 4, 1, 0, 5] 25 | bogoSort(a) 26 | print("Sorted array :") 27 | for i in range(len(a)): 28 | print (a[i]) 29 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bogo Sort/sort.py: -------------------------------------------------------------------------------- 1 | import random 2 | 3 | def bogosort(array): 4 | random.shuffle(array) 5 | while array != sorted(array): 6 | random.shuffle(array) 7 | return array 8 | 9 | numbers = [2,4,6,8,10,9,7,5,3,1] 10 | print(numbers) 11 | numbers = bogosort(numbers) 12 | print(numbers) -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Bubble Sort/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/BubbleSort.py: -------------------------------------------------------------------------------- 1 | def bubble_sort(a): 2 | n = len(a) 3 | 4 | for i in range(n): 5 | # Last i elements are already in place 6 | for j in range(0, n - i - 1): 7 | # Traverse the array from 0 to n-i-1 8 | # Swap if the element found is greater than the next element 9 | if a[j] > a[j + 1]: 10 | a[j], a[j + 1] = a[j + 1], a[j] 11 | 12 | 13 | if __name__ == '__main__': 14 | a = [64, 34, 25, 12, 22, 11, 90] 15 | bubble_sort(a) 16 | print("Sorted array is:") 17 | for i in range(len(a)): 18 | print("%d" % a[i]) 19 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/Bubble_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n, arr[100]; 5 | printf("Enter no of elements: "); 6 | scanf("%d", &n); 7 | printf("Enter %d elements now: ", n); 8 | for(int i = 0; i < n; i++) { 9 | scanf("%d", &arr[i]); 10 | } 11 | 12 | printf("Before the sort: \n"); 13 | for(int i = 0; i < n; i++) { 14 | printf("%d ", arr[i]); 15 | } 16 | 17 | //Bubble sort algo 18 | for(int i = 0; i < n-1; i++) { 19 | for(int j = 0; j < n-i-1; j++) { 20 | if(arr[j] > arr[j+1]) { 21 | //Swapping the elements 22 | int temp = arr[j]; 23 | arr[j] = arr[j+1]; 24 | arr[j+1] = temp; 25 | } 26 | } 27 | } 28 | 29 | printf("\nAfter the sort: \n"); 30 | for(int i = 0; i < n; i++) { 31 | printf("%d ", arr[i]); 32 | } 33 | printf("\n"); 34 | } -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/Bubble_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n, arr[100]; 8 | cout << "Enter no of elements: "; 9 | cin >> n; 10 | cout << "Enter " << n << " elements now: "; 11 | for (int i = 0; i < n; i++) 12 | { 13 | cin >> arr[i]; 14 | } 15 | 16 | cout << "Before the sort: "; 17 | for (int i = 0; i < n; i++) 18 | { 19 | cout << arr[i] << " "; 20 | } 21 | 22 | //Bubble sort algo 23 | for (int i = 0; i < n - 1; i++) 24 | { 25 | for (int j = 0; j < n - i - 1; j++) 26 | { 27 | if (arr[j] > arr[j + 1]) 28 | { 29 | //Swapping the elements 30 | int temp = arr[j]; 31 | arr[j] = arr[j + 1]; 32 | arr[j + 1] = temp; 33 | } 34 | } 35 | } 36 | 37 | cout << "\nAfter the sort: "; 38 | for (int i = 0; i < n; i++) 39 | { 40 | cout << arr[i] << " "; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Bubble Sort/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/bubbleSort.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | 3 | template 4 | void bubbleSort(T array[], int length) { 5 | for (int i = 0; i < length; i++) { 6 | for (int j = 0; j < length - 1; j++) { 7 | if (array[j] > array[j + 1]) { 8 | T temp = array[j]; 9 | array[j] = array[j + 1]; 10 | array[j + 1] = temp; 11 | } 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/bubble_sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int n, arr[100]; 5 | printf("Enter no of elements: "); 6 | scanf("%d", &n); 7 | printf("Enter %d elements now: ", n); 8 | for(int i = 0; i < n; i++) { 9 | scanf("%d", &arr[i]); 10 | } 11 | 12 | printf("Before the sort: \n"); 13 | for(int i = 0; i < n; i++) { 14 | printf("%d ", arr[i]); 15 | } 16 | 17 | //Bubble sort algo 18 | for(int i = 0; i < n-1; i++) { 19 | for(int j = 0; j < n-i-1; j++) { 20 | if(arr[j] > arr[j+1]) { 21 | //Swapping the elements 22 | int temp = arr[j]; 23 | arr[j] = arr[j+1]; 24 | arr[j+1] = temp; 25 | } 26 | } 27 | } 28 | 29 | printf("\nAfter the sort: \n"); 30 | for(int i = 0; i < n; i++) { 31 | printf("%d ", arr[i]); 32 | } 33 | printf("\n"); 34 | } -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Bubble Sort/bubble_sort.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | public class BubbleSort 4 | { 5 | 6 | public int[] bubblesort(int[] array) { 7 | while(true) { 8 | int swap_count = 0; 9 | for(int i=0; iarray[i+1]) { 11 | int swap = array[i]; 12 | array[i] = array[i+1]; 13 | array[i+1] = swap; 14 | swap_count += 1; 15 | } 16 | } 17 | if(swap_count == 0) { 18 | break; 19 | } 20 | } 21 | return array; 22 | } 23 | 24 | public static void Main(string[] args) 25 | { 26 | int[] arr = new int[6]{1, 6, 2, 8, 2, 3}; 27 | arr = new BubbleSort().bubblesort(arr); 28 | Console.WriteLine("Sorted array is"); 29 | for(int i=0;i arr[j+1]) 10 | { 11 | // swap temp and arr[i] 12 | int temp = arr[j]; 13 | arr[j] = arr[j+1]; 14 | arr[j+1] = temp; 15 | } 16 | } 17 | 18 | /* Prints the array */ 19 | void printArray(int arr[]) 20 | { 21 | int n = arr.length; 22 | for (int i=0; i arr[j+1] : 18 | arr[j], arr[j+1] = arr[j+1], arr[j] 19 | swapped = True 20 | 21 | # IF no two elements were swapped 22 | # by inner loop, then break 23 | if swapped == False: 24 | break 25 | 26 | # Driver code to test above 27 | arr = [64, 34, 25, 12, 22, 11, 90] 28 | 29 | bubbleSort(arr) 30 | 31 | print ("Sorted array :") 32 | for i in range(len(arr)): 33 | print ("%d" %arr[i],end=" ") -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Counting Sort/Java/CountingSort.java: -------------------------------------------------------------------------------- 1 | class CountingSort { 2 | 3 | void sort(int arr[]) { 4 | int n = arr.length; 5 | 6 | int output[] = new int[n]; 7 | 8 | int count[] = new int[256]; 9 | for (int i=0; i<256; ++i) 10 | count[i] = 0; 11 | 12 | for (int i=0; i=0; i--) 20 | { 21 | output[count[arr[i]]-1] = arr[i]; 22 | --count[arr[i]]; 23 | } 24 | 25 | for (int i = 0; i 1): 11 | i = min(index + fib2, (len(arr)-1)) 12 | if (arr[i] < key): 13 | fib = fib1 14 | fib1 = fib2 15 | fib2 = fib - fib1 16 | index = i 17 | elif (arr[i] > key): 18 | fib = fib2 19 | fib1 = fib1 - fib2 20 | fib2 = fib - fib1 21 | else : 22 | return i 23 | if(fib1 and index < (len(arr)-1) and arr[index+1] == key): 24 | return index+1 25 | return -1 26 | 27 | 28 | key= 15 29 | arr = [5, 10, 15, 20, 25, 30, 35] 30 | ans = FibonacciSearch(arr, key) 31 | print(ans) 32 | if (ans): 33 | print("Found at "+ str(ans+1) +" position") 34 | else: 35 | print("Not Found") 36 | 37 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Heap Sort/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Heap Sort/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Heap Sort/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Heap Sort/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Insertion Sort/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/C++/InsertionSort.cpp: -------------------------------------------------------------------------------- 1 | // C++ program for insertion sort 2 | #include 3 | using namespace std; 4 | 5 | /* Function to sort an array using insertion sort*/ 6 | void insertionSort(int arr[], int n) 7 | { 8 | int i, key, j; 9 | for (i = 1; i < n; i++) 10 | { 11 | key = arr[i]; 12 | j = i - 1; 13 | 14 | /* Move elements of arr[0..i-1], that are 15 | greater than key, to one position ahead 16 | of their current position */ 17 | while (j >= 0 && arr[j] > key) 18 | { 19 | arr[j + 1] = arr[j]; 20 | j = j - 1; 21 | } 22 | arr[j + 1] = key; 23 | } 24 | } 25 | 26 | // A utility function to print an array of size n 27 | void printArray(int arr[], int n) 28 | { 29 | int i; 30 | for (i = 0; i < n; i++) 31 | cout << arr[i] << " "; 32 | cout << endl; 33 | } 34 | 35 | /* Driver code */ 36 | int main() 37 | { 38 | int arr[] = { 12, 11, 13, 5, 6 }; 39 | int n = sizeof(arr) / sizeof(arr[0]); 40 | 41 | insertionSort(arr, n); 42 | printArray(arr, n); 43 | 44 | return 0; 45 | } 46 | 47 | // This is code is contributed by rathbhupendra 48 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/Insertion-Sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | void insertionSort(int array[], int size) 3 | { 4 | for (int i = 1; i < size; i++) 5 | { 6 | int temp = array[i]; 7 | int j = i - 1; 8 | while (temp < array[j] && j >= 0) 9 | { 10 | array[j + 1] = array[j]; 11 | --j; 12 | } 13 | array[j + 1] = temp; 14 | } 15 | } 16 | void printArray(int array[], int size) 17 | { 18 | for (int i = 0; i < size; i++) 19 | { 20 | printf("%d ", array[i]); 21 | } 22 | printf("\n"); 23 | } 24 | int main() 25 | { 26 | int arr[] = {9, 5, 1, 4, 3}; 27 | int size = sizeof(arr) / sizeof(arr[0]); 28 | insertionSort(arr, size); 29 | printf("Sorted array :\n"); 30 | printArray(arr, size); 31 | } 32 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/Python/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Insertion Sort/Python/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/Python/InsertionSort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Insertion Sort 2 | 3 | # Function to do insertion sort 4 | def insertionSort(arr): 5 | 6 | # Traverse through 1 to len(arr) 7 | for i in range(1, len(arr)): 8 | 9 | key = arr[i] 10 | 11 | # Move elements of arr[0..i-1], that are 12 | # greater than key, to one position ahead 13 | # of their current position 14 | j = i-1 15 | while j >= 0 and key < arr[j] : 16 | arr[j + 1] = arr[j] 17 | j -= 1 18 | arr[j + 1] = key 19 | 20 | 21 | # Driver code to test above 22 | arr = [12, 11, 13, 5, 6] 23 | insertionSort(arr) 24 | for i in range(len(arr)): 25 | print ("% d" % arr[i]) 26 | 27 | # This code is contributed by Mohit Kumra 28 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/README.md: -------------------------------------------------------------------------------- 1 | Insertion Sort 2 | Insertion sort is a simple sorting algorithm that works the way we sort playing cards in our hands. 3 | Algorithm 4 | // Sort an arr[] of size n 5 | insertionSort(arr, n) 6 | Loop from i = 1 to n-1. 7 | a) Pick element arr[i] and insert it into sorted sequence arr[0…i-1] 8 | 9 | Example: 10 | 12, 11, 13, 5, 6 11 | 12 | Let us loop for i = 1 (second element of the array) to 4 (last element of the array) 13 | 14 | i = 1. Since 11 is smaller than 12, move 12 and insert 11 before 12 15 | 11, 12, 13, 5, 6 16 | 17 | i = 2. 13 will remain at its position as all elements in A[0..I-1] are smaller than 13 18 | 11, 12, 13, 5, 6 19 | 20 | i = 3. 5 will move to the beginning and all other elements from 11 to 13 will move one position ahead of their current position. 21 | 5, 11, 12, 13, 6 22 | 23 | i = 4. 6 will move to position after 5, and elements from 11 to 13 will move one position ahead of their current position. 24 | 5, 6, 11, 12, 13 -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/insertion_sort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Insertion Sort 2 | 3 | # Function to do insertion sort 4 | def insertionSort(arr): 5 | 6 | # Traverse through 1 to len(arr) 7 | for i in range(1, len(arr)): 8 | 9 | key = arr[i] 10 | 11 | # Move elements of arr[0..i-1], that are 12 | # greater than key, to one position ahead 13 | # of their current position 14 | j = i-1 15 | while j >=0 and key < arr[j] : 16 | arr[j+1] = arr[j] 17 | j -= 1 18 | arr[j+1] = key 19 | 20 | 21 | # Driver code to test above 22 | arr = [12, 11, 13, 5, 6] 23 | insertionSort(arr) 24 | print ("Sorted array is:") 25 | for i in range(len(arr)): 26 | print ("%d" %arr[i]) 27 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Insertion Sort/insertion_sort_python.py: -------------------------------------------------------------------------------- 1 | def insertionSort(nlist): 2 | for index in range(1,len(nlist)): 3 | 4 | currentvalue = nlist[index] 5 | position = index 6 | 7 | while position>0 and nlist[position-1]>currentvalue: 8 | nlist[position]=nlist[position-1] 9 | position = position-1 10 | 11 | nlist[position]=currentvalue 12 | 13 | nlist = [15,30,25,100,6,27,83,120] 14 | insertionSort(nlist) 15 | print(nlist) 16 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Jump Search/jump_search.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Implementation of Jump search 3 | Time Complexity: O(sqrt(n)) 4 | Space Complexity: O(1) 5 | ''' 6 | import math 7 | 8 | def jump_search(arr, x): 9 | l = len(arr) 10 | 11 | p_ind = 0 #previous_index 12 | c_ind = 0 #current_index 13 | step = int(math.sqrt(len(arr))) #optimal jump_step 14 | 15 | #keep looking forward till the indexed element becomes greater than the searched element and then do linear search 16 | while c_ind <= l and x>arr[min(c_ind, l)]: 17 | p_ind = c_ind 18 | c_ind += step 19 | 20 | #linear search 21 | for i in range(p_ind+1, c_ind+1): 22 | if x == arr[i]: 23 | return i 24 | 25 | return -1 26 | 27 | 28 | arr = [2,3,4,10,40] 29 | x = 40 30 | 31 | index = jump_search(arr, x) 32 | if index==-1: 33 | print("Element not present in list") 34 | else: 35 | print("Element",x,"is present at",index) 36 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Linear Search/LinearSearch.java: -------------------------------------------------------------------------------- 1 | // Java code for linearly searching x in arr[]. If x 2 | // is present then return its location, otherwise 3 | // return -1 4 | 5 | class GFG 6 | { 7 | public static int search(int arr[], int x) 8 | { 9 | int n = arr.length; 10 | for(int i = 0; i < n; i++) 11 | { 12 | if(arr[i] == x) 13 | return i; 14 | } 15 | return -1; 16 | } 17 | 18 | public static void main(String args[]) 19 | { 20 | int arr[] = { 2, 3, 4, 10, 40 }; 21 | int x = 10; 22 | 23 | int result = search(arr, x); 24 | if(result == -1) 25 | System.out.print("Element is not present in array"); 26 | else 27 | System.out.print("Element is present at index " + result); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Linear Search/Linear_search.py: -------------------------------------------------------------------------------- 1 | #Defining function for Linear Search 2 | def Linear_Search(input_list, key): 3 | flag = 0 4 | #Iterating each item in the list and comparing it with the key searching for 5 | for i in range(len(input_list)): 6 | if(input_list[i] == key): 7 | #If key matches with any of the list items 8 | flag = 1 9 | print("\nKey is found in the position: {}" .format(i)) 10 | #If key not found 11 | if(flag == 0): 12 | print("\nKey not found") 13 | 14 | #Input List 15 | input_list = [11,12,13,14,15,16,17,18,19] 16 | print("List available is {}" .format(input_list)) 17 | #Getting Key from user 18 | key = input("\nEnter key to be searched in the list") 19 | key = int(key) 20 | #Calling function defined to perform Linear Search 21 | Linear_Search(input_list, key) 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Linear Search/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Linear Search/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Linear Search/linear_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void linear_search(int *arr, int n, int x) 4 | { 5 | int flag = 1; 6 | for (int i = 0; i < n; i++) 7 | { 8 | if (arr[i] == x) 9 | { 10 | printf("Element found at index %d", i); 11 | flag = 0; 12 | break; 13 | } 14 | } 15 | 16 | if (flag) 17 | { 18 | printf("Element is not present inside the array"); 19 | } 20 | } 21 | 22 | void display(int *arr, int n) 23 | { 24 | printf("\n\n"); 25 | for (int i = 0; i < n; i++) 26 | printf(" %d", arr[i]); 27 | } 28 | 29 | int main() 30 | { 31 | 32 | int n; 33 | printf("\n\nEnter number of elements "); 34 | scanf("%d", &n); 35 | int arr[n]; 36 | 37 | for (int i = 0; i < n; i++) 38 | scanf("%d", &arr[i]); 39 | 40 | display(arr, n); 41 | 42 | int find; 43 | printf("\n\nEnter which element you want to search "); 44 | scanf("%d", &find); 45 | 46 | linear_search(arr, n, find); 47 | 48 | return 0; 49 | } 50 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Linear Search/linearsearch.java: -------------------------------------------------------------------------------- 1 | // Java code for linearly searching x in arr[]. If x 2 | // is present then return its location, otherwise 3 | // return -1 4 | 5 | class GFG 6 | { 7 | public static int search(int arr[], int x) 8 | { 9 | int n = arr.length; 10 | for(int i = 0; i < n; i++) 11 | { 12 | if(arr[i] == x) 13 | return i; 14 | } 15 | return -1; 16 | } 17 | 18 | public static void main(String args[]) 19 | { 20 | int arr[] = { 2, 3, 4, 10, 40 }; 21 | int x = 10; 22 | 23 | int result = search(arr, x); 24 | if(result == -1) 25 | System.out.print("Element is not present in array"); 26 | else 27 | System.out.print("Element is present at index " + result); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Merge Sort/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Merge Sort/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/QuickSort/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/QuickSort/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/QuickSort/QuickSort_2.py: -------------------------------------------------------------------------------- 1 | def quicksort(alist, start, end): 2 | '''Sorts the list from indexes start to end - 1 inclusive.''' 3 | if end - start > 1: 4 | p = partition(alist, start, end) 5 | quicksort(alist, start, p) 6 | quicksort(alist, p + 1, end) 7 | 8 | 9 | def partition(alist, start, end): 10 | pivot = alist[start] 11 | i = start + 1 12 | j = end - 1 13 | 14 | while True: 15 | while (i <= j and alist[i] <= pivot): 16 | i = i + 1 17 | while (i <= j and alist[j] >= pivot): 18 | j = j - 1 19 | 20 | if i <= j: 21 | alist[i], alist[j] = alist[j], alist[i] 22 | else: 23 | alist[start], alist[j] = alist[j], alist[start] 24 | return j 25 | 26 | z=input() 27 | alist = input().split() 28 | alist = [int(x) for x in alist] 29 | quicksort(alist, 0, len(alist)) 30 | for i in alist: 31 | print(i, end = " ") 32 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/QuickSort/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/QuickSort/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Radix Sort/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Radix Sort/README.md -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Selection Sort/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Selection Sort/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Selection Sort/C/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Selection Sort/C/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Selection Sort/Python/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Selection Sort/Python/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Selection Sort/Python/SelectionSort.py: -------------------------------------------------------------------------------- 1 | # Python program for implementation of Selection 2 | # Sort 3 | import sys 4 | 5 | A = [64, 25, 12, 22, 11] 6 | 7 | # Traverse through all array elements 8 | for i in range(len(A)): 9 | 10 | # Find the minimum element in remaining 11 | # unsorted array 12 | min_idx = i 13 | for j in range(i + 1, len(A)): 14 | if A[min_idx] > A[j]: 15 | min_idx = j 16 | 17 | # Swap the found minimum element with 18 | # the first element 19 | A[i], A[min_idx] = A[min_idx], A[i] 20 | 21 | # Driver code to test above 22 | print("Sorted array") 23 | for i in range(len(A)): 24 | print("%d" % A[i]), 25 | -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Shell Sort/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/Searching & Sorting/Shell Sort/.DS_Store -------------------------------------------------------------------------------- /Algorithms/Searching & Sorting/Shell Sort/shellsort.py: -------------------------------------------------------------------------------- 1 | # A python program to sort array using shell sort 2 | def shellSort(alist): 3 | sublistcount = len(alist)//2 4 | while sublistcount > 0: 5 | for start_position in range(sublistcount): 6 | gap_InsertionSort(alist, start_position, sublistcount) 7 | 8 | print("After increments of size",sublistcount, "The list is",numberlist) 9 | 10 | sublistcount = sublistcount // 2 11 | 12 | def gap_InsertionSort(numberlist,start,gap): 13 | for i in range(start+gap,len(numberlist),gap): 14 | 15 | current_value = numberlist[i] 16 | position = i 17 | 18 | while position>=gap and numberlist[position-gap]>current_value: 19 | numberlist[position]=numberlist[position-gap] 20 | position = position-gap 21 | 22 | numberlist[position]=current_value 23 | 24 | 25 | numberlist = [14,46,43,27,57,41,45,21,70] 26 | shellSort(numberlist) 27 | print(numberlist) 28 | -------------------------------------------------------------------------------- /Algorithms/String/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Algorithms/String/.DS_Store -------------------------------------------------------------------------------- /Algorithms/String/NaiveString/NaiveSearch.java: -------------------------------------------------------------------------------- 1 | public class NaiveSearch { 2 | 3 | public static void search(String txt, String pat) 4 | { 5 | int M = pat.length(); 6 | int N = txt.length(); 7 | 8 | /* A loop to slide pat one by one */ 9 | for (int i = 0; i <= N - M; i++) { 10 | 11 | int j; 12 | 13 | /* For current index i, check for pattern 14 | match */ 15 | for (j = 0; j < M; j++) 16 | if (txt.charAt(i + j) != pat.charAt(j)) 17 | break; 18 | 19 | if (j == M) // if pat[0...M-1] = txt[i, i+1, ...i+M-1] 20 | System.out.println("Pattern found at index " + i); 21 | } 22 | } 23 | 24 | public static void main(String[] args) 25 | { 26 | String txt = "AABAACAADAABAAABAA"; 27 | String pat = "AABA"; 28 | search(txt, pat); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Algorithms/String/StringReverse/strRev.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Input: 'programming is fun' 3 | Output: 'fun is programming' 4 | ''' 5 | #Method 1 6 | s = 'programming is fun' 7 | l = s.split() 8 | l.reverse() 9 | s = ' '.join(l) 10 | print(s) 11 | 12 | 13 | #Method 2 14 | s = 'programming is fun' 15 | s = s[::-1] 16 | ln=len(s) 17 | a='' 18 | for i in s: 19 | if i == ' ': 20 | x = a[::-1] 21 | s = s.replace(a,x) 22 | a = '' 23 | else: 24 | a += i 25 | 26 | x=a[::-1] 27 | s=s.replace(a,x) 28 | print(s) 29 | 30 | #Method 3 31 | def reverse(s): 32 | str = "" 33 | for i in s: 34 | str = i + str 35 | return str 36 | 37 | s = "programming is fun" 38 | 39 | print ("The original string is : ",end="") 40 | print (s) 41 | 42 | print ("The reversed string(using loops) is : ",end="") 43 | print (reverse(s)) 44 | -------------------------------------------------------------------------------- /Algorithms/String/dnapatternmatching/dnapattern.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | import re as r 3 | dnapattern={ 4 | 'ATAACCGTACATACGAT':'Shrikant padhy', 5 | 'ATCCCGATGCTACATGG':'Shreyash iyyer', 6 | 'GTACCGATGGATTTCGA':'Shayantan Santra', 7 | 'CTACGATCGATATGCAT':'manthan Raut', 8 | 'ATTACCGATCATCGATA':'Alwar Goswami', 9 | 'ATGCATTATGATCGAAT':'Kagiso Rabada', 10 | 'ATCGATTATGATGGACT':'Mayank Tripathi', 11 | 'ATCCGATATCATCTAGC':'Pranay Solse', 12 | 'ATGAGCTATCATCTAGC':'Akilesh Salunkhe', 13 | 'ATACGGTATCCCGTATA':'Akshay Pawar', 14 | } 15 | dnacount=defaultdict(list) 16 | diseased=input("Enter the most Common pattern found in diseased person") 17 | for j in dnapattern.keys(): 18 | ls=[x.start() for x in r.finditer('('+'?'+'='+diseased+')',j)] 19 | dnacount[len(ls)]+=[dnapattern[j]] 20 | find=dnacount.get(max(dnacount.keys()),False) 21 | if(find==False or max(dnacount.keys())==0): 22 | print("Dna Pattern Unmatched") 23 | else: 24 | print("Dna pattern is more similar to the relative named:{}".format(find)) 25 | -------------------------------------------------------------------------------- /Algorithms/String/dnapatternmatching/readme.md: -------------------------------------------------------------------------------- 1 | Question: 2 | 3 | A forensic lab wants to know whether a deceased person’s DNA matches a set of known relatives. It is known that the closest relatives will have most of the DNA matching, and as the relationship becomes farther, the matching genes will be lesser. For this, the DNA pattern of the deceased is given and the DNA pattern of 10 likely relatives are given. Write a program to identify the family of the deceased. -------------------------------------------------------------------------------- /Algorithms/String/run-length-encoding/readme.md: -------------------------------------------------------------------------------- 1 | Run length Encoding is problem where we are suppose to find out the the number of consecutive occurence of character followed by the character itself 2 | 3 | for an example:INPUT:GOOD 4 | OUTPUT:1G2O1D 5 | 6 | INPUT:MONGOOSE 7 | output:1M1O1N1G2O1S1E11 -------------------------------------------------------------------------------- /Algorithms/String/run-length-encoding/rle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void main() 5 | { 6 | int status=1; 7 | char a[1000]; 8 | printf("Enter The String\n"); 9 | gets(&a[0]); 10 | int j,i=0; 11 | int count=0; 12 | while(i<=strlen(a)) 13 | { 14 | status=0; 15 | count=1; 16 | j=i+1; 17 | while(j<=strlen(a)) 18 | { 19 | if(a[i]==a[j]) 20 | { 21 | count+=1; 22 | } 23 | else 24 | { 25 | printf("%d",count); 26 | printf("%c",a[i]); 27 | status=1; 28 | i+=count; 29 | break; 30 | } 31 | j+=1; 32 | } 33 | if(status!=1) 34 | { 35 | i+=1; 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /Algorithms/divide_and_conquer/readme.md: -------------------------------------------------------------------------------- 1 | QUESTION: 2 | 3 | 4 | 5 | You are baby-sitting n children and have m > n cookies to divide between them. You must give each child exactly one cookie (of course, you cannot give the same cookie to two different children). Each child has a greed factor gi,1 ≤ i ≤ n which is the minimum size of a cookie that the child will be content with; and each cookie has a size sj , 1 ≤ j ≤ m. Your goal is to maximize the number of content children, i.e.., children i assigned a cookie j with gi ≤ s . -------------------------------------------------------------------------------- /Algorithms/largest_sum_of_alternate.md: -------------------------------------------------------------------------------- 1 | Here In this algorithm the array is given and we are suppose to findout the maximum sum of subarray,but the rule is that the element should not be adjacent to the element which has already been considered. 2 | 3 | example: 4 | input:a=[1,0,3,8,1] 5 | output:9 6 | 9 is given by a[0]+a[3] 7 | 8 | if we consider,a[0] then as per the given constraint of this problem we cant consider a[1] because a[0] has been already considered. 9 | in this way we have to pick up all the possibilities and consider the one which gives maximum sum and print the sum 10 | 11 | similarly 12 | input:a=[0,8,-1] 13 | output=8 14 | 15 | input:a=[1,4,4,5,-2,14,120,10,-30] 16 | output:129 17 | given by a[1]+a[3]+a[6] -------------------------------------------------------------------------------- /Algorithms/largest_sum_of_alternate.py: -------------------------------------------------------------------------------- 1 | 2 | def find(arr,i): 3 | if i>len(arr)-1: 4 | return 0 5 | elif i==len(arr)-1: 6 | return arr[i] 7 | else: 8 | if vis[i]==1: 9 | return dp[i] 10 | else: 11 | ans=0 12 | j=2 13 | while j 4 -> 3) + (5 -> 6 -> 4) 13 | Output: 7 -> 0 -> 8 14 | Explanation: 342 + 465 = 807. 15 | 16 | 17 | #### tags Medium 18 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Questions/BinarySearchTree.md: -------------------------------------------------------------------------------- 1 | ### Airbnb 2 | 3 | ### easy 4 | 5 | ``` 6 | Given an array where elements are sorted in ascending order, convert it to a height balanced BST. 7 | 8 | For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1. 9 | 10 | Example: 11 | 12 | Given the sorted array: [-10,-3,0,5,9], 13 | 14 | One possible answer is: [0,-3,9,-10,null,5], which represents the following height balanced BST: 15 | 16 | 0 17 | / \ 18 | -3 9 19 | / / 20 | -10 5 21 | 22 | ``` 23 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Questions/HappyNumber.md: -------------------------------------------------------------------------------- 1 | 2 | ### airbnb 3 | ### tags maths 4 | 5 | ``` 6 | Write an algorithm to determine if a number is "happy". 7 | 8 | A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1. Those numbers for which this process ends in 1 are happy numbers. 9 | 10 | Example: 11 | 12 | Input: 19 13 | Output: true 14 | Explanation: 15 | 12 + 92 = 82 16 | 82 + 22 = 68 17 | 62 + 82 = 100 18 | 12 + 02 + 02 = 1 19 | 20 | ``` 21 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Questions/MergeSort.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Airbnb 4 | 5 | ### tags hard linkedList | Divide and Conquer | heap 6 | 7 | ``` 8 | Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. 9 | 10 | Example: 11 | 12 | Input: 13 | [ 14 | 1->4->5, 15 | 1->3->4, 16 | 2->6 17 | ] 18 | Output: 1->1->2->3->4->4->5->6 19 | 20 | ``` 21 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Questions/MiniParser.md: -------------------------------------------------------------------------------- 1 | ### Airbnb 2 | 3 | ### tags Medium 4 | 5 | ``` 6 | Given a nested list of integers represented as a string, implement a parser to deserialize it. 7 | 8 | Each element is either an integer, or a list -- whose elements may also be integers or other lists. 9 | 10 | Note: You may assume that the string is well-formed: 11 | 12 | String is non-empty. 13 | String does not contain white spaces. 14 | String contains only digits 0-9, [, - ,, ]. 15 | Example 1: 16 | 17 | Given s = "324", 18 | 19 | You should return a NestedInteger object which contains a single integer 324. 20 | Example 2: 21 | 22 | Given s = "[123,[456,[789]]]", 23 | 24 | Return a NestedInteger object containing a nested list with 2 elements: 25 | 26 | ``` 27 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Questions/SingleNumber.md: -------------------------------------------------------------------------------- 1 | 2 | ### Airbnb 3 | 4 | ### tags hash-table 5 | 6 | ### tags - easy 7 | 8 | ``` 9 | Given a non-empty array of integers, every element appears twice except for one. Find that single one. 10 | 11 | Note: 12 | 13 | Your algorithm should have a linear runtime complexity. Could you implement it without using extra memory? 14 | 15 | Example 1: 16 | 17 | Input: [2,2,1] 18 | Output: 1 19 | Example 2: 20 | 21 | Input: [4,1,2,1,2] 22 | Output: 4 23 | 24 | ``` 25 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Questions/TwoSum.md: -------------------------------------------------------------------------------- 1 | 2 | ## Airbnb 3 | 4 | ### TwoSum 5 | 6 | ``` 7 | Given an array of integers, return indices of the two numbers such that they add up to a specific target. 8 | 9 | You may assume that each input would have exactly one solution, and you may not use the same element twice. 10 | ``` 11 | Example: 12 | 13 | Given nums = [2, 7, 11, 15], target = 9, 14 | 15 | Because nums[0] + nums[1] = 2 + 7 = 9, 16 | return [0, 1] 17 | 18 | Given nums = [3,2,3], target = 6 19 | return [0, 2] 20 | 21 | ### tags - Easy 22 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Questions/Validparentheses.md: -------------------------------------------------------------------------------- 1 | 2 | ### Airbnb 3 | 4 | ### tags Easy | String, Stacks 5 | 6 | ``` 7 | 8 | Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. 9 | 10 | An input string is valid if: 11 | 12 | Open brackets must be closed by the same type of brackets. 13 | Open brackets must be closed in the correct order. 14 | Note that an empty string is also considered valid. 15 | 16 | Example 1: 17 | 18 | Input: "()" 19 | Output: true 20 | Example 2: 21 | 22 | Input: "()[]{}" 23 | Output: true 24 | Example 3: 25 | 26 | Input: "(]" 27 | Output: false 28 | 29 | ``` 30 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/README.md: -------------------------------------------------------------------------------- 1 | ## Hacktoberfest 2 | 3 | 4 | ## Guidelines 5 | 6 | There are two sections here: 7 | * This markdown file consists of company specific multiple questions. 8 | * Further commit Your file to the solution section. 9 | * Follow the Contrubution Guidlines for futher instructions 10 | 11 | See [Contributor.md](Contributor.md) 12 | 13 | 14 | Source 15 | [Leetcode](https://leetcode.com) 16 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Solutions/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Company Specific Interview Questions/Airbnb/Solutions/.DS_Store -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Solutions/C/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ``` HacktoberFest 2019 ``` 4 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Solutions/Cpp/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ``` HacktoberFest 2019 ``` 4 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Solutions/Cpp/Validparentheses.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s; 7 | cin >> s; 8 | stack st; 9 | map value; 10 | value['('] = value[')'] = 1; 11 | value['['] = value[']'] = 2; 12 | value['{'] = value['}'] = 3; 13 | for(int i = 0; i < s.length(); i++) 14 | { 15 | if(!st.empty()) 16 | { 17 | if(value[s[i]] == value[st.top()]) 18 | st.pop(); 19 | else 20 | st.push(s[i]); 21 | } 22 | else 23 | st.push(s[i]); 24 | } 25 | if(st.empty()) cout << "true"; 26 | else cout << "false"; 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Solutions/Java/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ``` HacktoberFest 2019 ``` 4 | -------------------------------------------------------------------------------- /Company Specific Interview Questions/Airbnb/Solutions/Java/TwoSum.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | // this is two sum for airbnb 3 | public class TwoSum { 4 | public static void main(String[] args){ 5 | Scanner cin=new Scanner(System.in); 6 | int n=cin.nextInt(); 7 | int[] nms=new int[n]; 8 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | 7 | string Original; 8 | string copy[10]; 9 | int match[10]; 10 | cin>>Original; 11 | for (int i=0;i<10;i++) 12 | cin>>copy[i]; 13 | 14 | int count_max=0; 15 | 16 | for(int j=0;j<10;j++) 17 | { 18 | int count=0; 19 | for (int i=0 ;i 2 | #include 3 | using namespace std; 4 | bitset<30> col,d1,d2; 5 | //N queens using bitsets 6 | void solve(int r,int n,int *ans){ 7 | if(r==n){ 8 | *ans=*ans+1; 9 | return; 10 | } 11 | //Recursive case 12 | for(int c=0;c>n; 30 | if(n==12){ 31 | cout<<14200< list=new ArrayList<>(); 8 | for(int i=0;i 2 | int main(){ 3 | int first = 0; 4 | int second = 1; 5 | int next = 0; 6 | int num; 7 | printf("Number of element: \n"); 8 | scanf("%d", &num); 9 | int i; 10 | for (i = 1; i <= num; i++){ 11 | if (i <= 1) 12 | next = i; 13 | else{ 14 | next = first + second; 15 | first = second; 16 | second = next; 17 | //printf("%d\n", next); 18 | } 19 | } 20 | printf("%d term of Fibbonacci is %d", num , next); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Data Structures/Fibonacci Heap/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Fibonacci Heap/C/readme.md -------------------------------------------------------------------------------- /Data Structures/Fibonacci Heap/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Fibonacci Heap/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Fibonacci Heap/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Fibonacci Heap/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Fibonacci Heap/Python/fibonacci.py: -------------------------------------------------------------------------------- 1 | def print_fibonacci(num): 2 | 3 | first, second = 0, 1 4 | print(first) 5 | print(second) 6 | num = num - 2 7 | 8 | while num > 0: 9 | 10 | num = num - 1 11 | first, second = second, first + second 12 | print(second) 13 | 14 | def main(): 15 | 16 | n = int(input("\nEnter the number of terms of Fibonacci series to be printed: ")) 17 | print_fibonacci(n) 18 | 19 | if __name__ == "__main__": 20 | main() 21 | -------------------------------------------------------------------------------- /Data Structures/Fibonacci Heap/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Fibonacci Heap/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Graph Traversal/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graph Traversal/.DS_Store -------------------------------------------------------------------------------- /Data Structures/Graph Traversal/Bellman Ford Algorithm/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graph Traversal/Bellman Ford Algorithm/README.md -------------------------------------------------------------------------------- /Data Structures/Graph Traversal/Breadth First Search/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graph Traversal/Breadth First Search/README.md -------------------------------------------------------------------------------- /Data Structures/Graph Traversal/Breadth First Search/bfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int a[20][20],q[20],visited[20],n,i,j,f=0,r=-1; 4 | void bfs(int v) { 5 | for (i=1;i<=n;i++) 6 | if(a[v][i] && !visited[i]) 7 | q[++r]=i; 8 | if(f<=r) { 9 | visited[q[f]]=1; 10 | bfs(q[f++]); 11 | } 12 | } 13 | void main() { 14 | int v; 15 | clrscr(); 16 | printf("\n Enter the number of vertices:"); 17 | scanf("%d",&n); 18 | for (i=1;i<=n;i++) { 19 | q[i]=0; 20 | visited[i]=0; 21 | } 22 | printf("\n Enter graph data in matrix form:\n"); 23 | for (i=1;i<=n;i++) 24 | for (j=1;j<=n;j++) 25 | scanf("%d",&a[i][j]); 26 | printf("\n Enter the starting vertex:"); 27 | scanf("%d",&v); 28 | bfs(v); 29 | printf("\n The node which are reachable are:\n"); 30 | for (i=1;i<=n;i++) 31 | if(visited[i]) 32 | printf("%d\t",i); else 33 | printf("\n Bfs is not possible"); 34 | getch(); 35 | } 36 | -------------------------------------------------------------------------------- /Data Structures/Graph Traversal/Depth First Search/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graph Traversal/Depth First Search/README.md -------------------------------------------------------------------------------- /Data Structures/Graph Traversal/Depth First Search/dfs.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void DFS(int); 4 | int G[10][10],visited[10],n; //n is no of vertices and graph is sorted in array G[10][10] 5 | 6 | void main() 7 | { 8 | int i,j; 9 | printf("Enter number of vertices:"); 10 | 11 | scanf("%d",&n); 12 | 13 | //read the adjecency matrix 14 | printf("\nEnter adjecency matrix of the graph:"); 15 | 16 | for(i=0;i 0: 14 | dp[u][v] = G[u][v] 15 | 16 | for k in range(len_g): 17 | for u in range(len_g): 18 | for v in range(len_g): 19 | if dp[u][v] > dp[u][k] + dp[k][v]: 20 | dp[u][v] = dp[u][k] + dp[k][v] 21 | return dp 22 | 23 | G = [ 24 | [0, 1, 2, 0], 25 | [0,0,0,1], 26 | [0,0,0,3], 27 | [0,0,0,0] 28 | ] 29 | print(floyd(G)) -------------------------------------------------------------------------------- /Data Structures/Graphs/Floyd-Warshall Algorithm/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Floyd-Warshall Algorithm/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Kruskal's Algorithm/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Kruskal's Algorithm/C/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Kruskal's Algorithm/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Kruskal's Algorithm/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Kruskal's Algorithm/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Kruskal's Algorithm/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Kruskal's Algorithm/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Kruskal's Algorithm/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Prim's Algorithm/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Prim's Algorithm/C/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Prim's Algorithm/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Prim's Algorithm/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Prim's Algorithm/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Prim's Algorithm/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Prim's Algorithm/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Prim's Algorithm/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Topological Sort/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Topological Sort/C/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Topological Sort/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Topological Sort/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Topological Sort/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Topological Sort/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Graphs/Topological Sort/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Graphs/Topological Sort/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Hash Tables/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Hash Tables/C/readme.md -------------------------------------------------------------------------------- /Data Structures/Hash Tables/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Hash Tables/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Hash Tables/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Hash Tables/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Hash Tables/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Hash Tables/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Heap/C/readme.md: -------------------------------------------------------------------------------- 1 | Max heap in C. 2 | First build a maxHeapify function. 3 | -------------------------------------------------------------------------------- /Data Structures/Heap/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Heap/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Heap/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Heap/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Heap/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Heap/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Palindrome/C_palindrome.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // A function to check if a string str is palindrome 5 | void isPalindrome(char str[]) 6 | { 7 | // Start from leftmost and rightmost corners of str 8 | int l = 0; 9 | int h = strlen(str) - 1; 10 | 11 | // Keep comparing characters while they are same 12 | while (h > l) 13 | { 14 | if (str[l++] != str[h--]) 15 | { 16 | printf("%s is Not Palindrome", str); 17 | return; 18 | } 19 | } 20 | printf("%s is palindrome", str); 21 | } 22 | 23 | // Driver program to test above function 24 | int main() 25 | { 26 | char a[10]; 27 | printf("Enter a string: "); 28 | gets(a); 29 | isPalindrome(a); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Data Structures/Palindrome/Cpp_palindrome.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | char string1[20]; 8 | int i, length; 9 | int flag = 0; 10 | cout << "Enter a string: "; 11 | cin >> string1; 12 | 13 | length = strlen(string1); 14 | 15 | for(i=0;i < length ;i++){ 16 | if(string1[i] != string1[length-i-1]){ 17 | flag = 1; 18 | break; 19 | } 20 | } 21 | 22 | if (flag) { 23 | cout << string1 << " is not a palindrome" << endl; 24 | } 25 | else { 26 | cout << string1 << " is a palindrome" << endl; 27 | } 28 | system("pause"); 29 | return 0; 30 | } -------------------------------------------------------------------------------- /Data Structures/Palindrome/Python_palindrome.py: -------------------------------------------------------------------------------- 1 | # function to check string is 2 | # palindrome or not 3 | def isPalindrome(s): 4 | 5 | # Using predefined function to 6 | # reverse to string print(s) 7 | rev = ''.join(reversed(s)) 8 | 9 | # Checking if both string are 10 | # equal or not 11 | if (s == rev): 12 | return True 13 | return False 14 | 15 | # main function 16 | s = str(input("Enter a string: ")) 17 | ans = isPalindrome(s) 18 | 19 | if (ans): 20 | print("Yes") 21 | else: 22 | print("No") -------------------------------------------------------------------------------- /Data Structures/Priority Queue/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Priority Queue/C/readme.md -------------------------------------------------------------------------------- /Data Structures/Priority Queue/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Priority Queue/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Priority Queue/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Priority Queue/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Priority Queue/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Priority Queue/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Queue/C/readme.md: -------------------------------------------------------------------------------- 1 | ## Prerequisite 2 | 3 | To run this program you should have a working c compiler 4 | 5 | ## Run Steps 6 | 7 | To run this first compile this file and then simply run it . 8 | 9 | -------------------------------------------------------------------------------- /Data Structures/Queue/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Queue/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Queue/Java/Queue.java: -------------------------------------------------------------------------------- 1 | 2 | public class Queue 3 | { 4 | public static void main(String[] args) 5 | { 6 | Queue q = new LinkedList<>(); 7 | 8 | for (int i=0; i<10; i++) 9 | q.add(i); 10 | 11 | // Display contents of the queue. 12 | System.out.println("Elements of queue-"+q); 13 | 14 | // To remove the head of queue. 15 | int removedele = q.remove(); 16 | System.out.println("removed element-" + removedele); 17 | 18 | System.out.println(q); 19 | 20 | // To view the head of queue 21 | int head = q.peek(); 22 | System.out.println("head of queue-" + head); 23 | 24 | // Rest all methods of collection interface, 25 | // Like size and contains can be used with this 26 | // implementation. 27 | int size = q.size(); 28 | System.out.println("Size of queue-" + size); 29 | } 30 | } -------------------------------------------------------------------------------- /Data Structures/Queue/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Queue/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Queue/Python/Queue.py: -------------------------------------------------------------------------------- 1 | class Queue: 2 | def __init__(self): 3 | self.items = [] 4 | 5 | def is_empty(self): 6 | return self.items == [] 7 | 8 | def enqueue(self, data): 9 | self.items.append(data) 10 | 11 | def dequeue(self): 12 | return self.items.pop(0) 13 | 14 | 15 | q = Queue() 16 | while True: 17 | print('enqueue ') 18 | print('dequeue') 19 | print('quit') 20 | do = input('What would you like to do? ').split() 21 | 22 | operation = do[0].strip().lower() 23 | if operation == 'enqueue': 24 | q.enqueue(int(do[1])) 25 | elif operation == 'dequeue': 26 | if q.is_empty(): 27 | print('Queue is empty.') 28 | else: 29 | print('Dequeued value: ', q.dequeue()) 30 | elif operation == 'quit': 31 | break 32 | -------------------------------------------------------------------------------- /Data Structures/Queue/Python/queue.py: -------------------------------------------------------------------------------- 1 | class Queue: 2 | def __init__(self): 3 | self.items = [] 4 | 5 | def is_empty(self): 6 | return self.items == [] 7 | 8 | def enqueue(self, data): 9 | self.items.append(data) 10 | 11 | def dequeue(self): 12 | return self.items.pop(0) 13 | 14 | 15 | q = Queue() 16 | while True: 17 | print('enqueue ') 18 | print('dequeue') 19 | print('quit') 20 | do = input('What would you like to do? ').split() 21 | 22 | operation = do[0].strip().lower() 23 | if operation == 'enqueue': 24 | q.enqueue(int(do[1])) 25 | elif operation == 'dequeue': 26 | if q.is_empty(): 27 | print('Queue is empty.') 28 | else: 29 | print('Dequeued value: ', q.dequeue()) 30 | elif operation == 'quit': 31 | break 32 | -------------------------------------------------------------------------------- /Data Structures/Queue/Python/queueinpy.py: -------------------------------------------------------------------------------- 1 | from collections import deque 2 | 3 | # Initializing a Queue object 4 | Q = deque() 5 | # Inserting to the Queue 6 | Q.append(1) 7 | Q.append(2) 8 | Q.append(3) 9 | # Printing the Queue 10 | print(list(Q)) 11 | # Popping an element from the created Queue (i.e., which pops from the front) 12 | Q.popleft() 13 | print(list(Q)) -------------------------------------------------------------------------------- /Data Structures/Queue/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Queue/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Queue/Python/simple_queue.py: -------------------------------------------------------------------------------- 1 | #Python Program for Queue Data Structure implementation 2 | 3 | class Queue: 4 | def __init__(self): 5 | self.items = [] 6 | 7 | def is_empty(self): 8 | return self.items == [] 9 | 10 | def enqueue(self, data): 11 | self.items.append(data) 12 | 13 | def dequeue(self): 14 | return self.items.pop(0) 15 | 16 | 17 | q = Queue() 18 | while True: 19 | print('enqueue ') 20 | print('dequeue') 21 | print('quit') 22 | do = input('What would you like to do? ').split() 23 | 24 | operation = do[0].strip().lower() 25 | if operation == 'enqueue': 26 | q.enqueue(int(do[1])) 27 | elif operation == 'dequeue': 28 | if q.is_empty(): 29 | print('Queue is empty.') 30 | else: 31 | print('Dequeued value: ', q.dequeue()) 32 | elif operation == 'quit': 33 | break 34 | -------------------------------------------------------------------------------- /Data Structures/Queue/Ruby/queue.rb: -------------------------------------------------------------------------------- 1 | #CREATED BY Ankur Pandey (Github : AnkDos) 2 | 3 | def enqueue(val,queue) 4 | queue << val #enqueue operation, '<<' represents 'push' in ruby . 5 | end 6 | 7 | def dequeue(queue) 8 | if queue.empty? == true #if queue is empty , its underflow 9 | "underflow" 10 | else 11 | queue.pop #dequeue operation , to pop out an element out of the queue 12 | end 13 | end 14 | 15 | queue = Queue.new # queue object 16 | 17 | while true 18 | puts "Select Operation(1 or 2)" 19 | puts "1.Enqueue" 20 | puts "2.Dequeue" 21 | inp = Integer(gets) 22 | if inp == 1 23 | puts "Enter value" 24 | val = Integer(gets) 25 | enqueue(val,queue) #First In 26 | elsif inp == 2 27 | val = dequeue(queue) #First Out 28 | puts val 29 | break if val == "underflow" 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /Data Structures/Singly Linked List/C/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Singly Linked List/C/readme.md -------------------------------------------------------------------------------- /Data Structures/Singly Linked List/C/singlylinkedlist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct Node { 5 | int data; 6 | struct Node* next; 7 | }; 8 | 9 | void printList(struct Node* n) 10 | { 11 | while (n != NULL) { 12 | printf(" %d ", n->data); 13 | n = n->next; 14 | } 15 | } 16 | 17 | int main() 18 | { 19 | struct Node* head = NULL; 20 | struct Node* second = NULL; 21 | struct Node* third = NULL; 22 | 23 | head = (struct Node*)malloc(sizeof(struct Node)); 24 | second = (struct Node*)malloc(sizeof(struct Node)); 25 | third = (struct Node*)malloc(sizeof(struct Node)); 26 | 27 | head->data = 1; 28 | head->next = second; 29 | 30 | second->data = 2; 31 | second->next = third; 32 | 33 | third->data = 3; 34 | third->next = NULL; 35 | 36 | printList(head); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Data Structures/Singly Linked List/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Singly Linked List/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Singly Linked List/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Singly Linked List/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Singly Linked List/Python/readme.md: -------------------------------------------------------------------------------- 1 | # This is a simple linkedlist in python 2 | -------------------------------------------------------------------------------- /Data Structures/Stack/C/dynamic_memory_allocation/readme.md: -------------------------------------------------------------------------------- 1 | This is stack program implemented in c language it uses the concept of dynamic memory allocation in c,structure and pointers. -------------------------------------------------------------------------------- /Data Structures/Stack/C/readme.md: -------------------------------------------------------------------------------- 1 | ## Stack 2 | 3 | ### Usage 4 | 5 | Compile: 6 | ```sh 7 | gcc stack2.c -o main 8 | ``` 9 | 10 | Run: 11 | ```sh 12 | ./main 13 | ``` 14 | -------------------------------------------------------------------------------- /Data Structures/Stack/CPP/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Stack/CPP/readme.md -------------------------------------------------------------------------------- /Data Structures/Stack/Java/Stack.java: -------------------------------------------------------------------------------- 1 | class Stack { 2 | static final int MAX = 1000; 3 | int top; 4 | int a[] = new int[MAX]; 5 | 6 | boolean isEmpty() { 7 | return (top < 0); 8 | } 9 | 10 | Stack() { 11 | top = -1; 12 | } 13 | 14 | boolean push(int x) { 15 | if (top >= (MAX - 1)) { 16 | System.out.println("Stack Overflow"); 17 | return false; 18 | } else { 19 | a[++top] = x; 20 | System.out.println(x + " pushed into stack"); 21 | return true; 22 | } 23 | } 24 | 25 | int pop() { 26 | if (top < 0) { 27 | System.out.println("Stack Underflow"); 28 | return 0; 29 | } lse { 30 | int x = a[top--]; 31 | return x; 32 | } 33 | } 34 | 35 | int peek() { 36 | if (top < 0) { 37 | System.out.println("Stack Underflow"); 38 | return 0; 39 | } else { 40 | int x = a[top]; 41 | return x; 42 | } 43 | } 44 | } 45 | 46 | class Main { 47 | public static void main(String args[]) { 48 | Stack s = new Stack(); 49 | s.push(10); 50 | s.push(20); 51 | s.push(30); 52 | System.out.println(s.pop() + " Popped from stack"); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Data Structures/Stack/Java/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Stack/Java/readme.md -------------------------------------------------------------------------------- /Data Structures/Stack/Python/readme.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Stack/Python/readme.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/.DS_Store -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/AVL Tree/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/AVL Tree/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Binary Search Tree/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Binary Search Tree/.DS_Store -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Binary Search Tree/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Binary Search Tree/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Depth of the Tree/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Depth of the Tree/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Fenwick Tree/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Fenwick Tree/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Fenwick Tree/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Fenwick Tree/a.out -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Height of the Tree/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Height of the Tree/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/In-Order Traversal/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/In-Order Traversal/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/In-Order Traversal/inorder.cpp: -------------------------------------------------------------------------------- 1 | // Prg for tree traversals in C++ 2 | #include 3 | using namespace std; 4 | 5 | // A class for a node 6 | struct Node 7 | { 8 | int data; 9 | struct Node *left, *right; 10 | Node(int data) 11 | { 12 | this->data = data; 13 | left = right = NULL; 14 | } 15 | }; 16 | 17 | // INORDER Traversal 18 | void printInorder(struct Node *node) 19 | { 20 | if (node == NULL) 21 | return; 22 | printInorder(node->left); // recur on left child 23 | cout << node->data << " "; // print value 24 | printInorder(node->right); // recur on right child 25 | } 26 | 27 | // MAIN 28 | int main() 29 | { 30 | struct Node *root = new Node(1); 31 | root->left = new Node(2); 32 | root->right = new Node(3); 33 | root->left->left = new Node(4); 34 | root->left->right = new Node(5); 35 | 36 | cout << "\nInorder traversal of binary tree is \n"; 37 | printInorder(root); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/In-Order Traversal/inorder.js: -------------------------------------------------------------------------------- 1 | // Prg for tree traversals in JS 2 | 3 | function Node(data) { 4 | this.data = data; 5 | this.left = null; 6 | this.right = null; 7 | } 8 | 9 | // Creating Nodes 10 | var root = new Node(1); 11 | var n1 = new Node(2); 12 | var n2 = new Node(3); 13 | var n3 = new Node(4); 14 | var n4 = new Node(5); 15 | 16 | // Setting Children 17 | root.left = n1; 18 | root.right = n2; 19 | n1.left = n3; 20 | n1.right = n4; 21 | 22 | 23 | // INORDER Traversal 24 | function in_order(root, nodes) { 25 | if (root && root.left) { 26 | in_order(root.left, nodes); 27 | } 28 | console.log(root.data); 29 | if (root && root.right) { 30 | in_order(root.right, nodes); 31 | } 32 | return nodes; 33 | } 34 | 35 | 36 | // MAIN 37 | console.log("InOrder Traversal: ") 38 | in_order(root, []); 39 | -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Lowest Common Ancestor in BST/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Lowest Common Ancestor in BST/.DS_Store -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Post-Order Traversal/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Post-Order Traversal/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Post-Order Traversal/postorder.cpp: -------------------------------------------------------------------------------- 1 | // Prg for tree traversals in C++ 2 | #include 3 | using namespace std; 4 | 5 | // A class for a node 6 | struct Node 7 | { 8 | int data; 9 | struct Node *left, *right; 10 | Node(int data) 11 | { 12 | this->data = data; 13 | left = right = NULL; 14 | } 15 | }; 16 | 17 | 18 | // POSTORDER Traversal 19 | void printPostorder(struct Node *node) 20 | { 21 | if (node == NULL) 22 | return; 23 | printPostorder(node->left); // recur on left child 24 | printPostorder(node->right); // recur on right child 25 | cout << node->data << " "; // print value 26 | } 27 | 28 | 29 | // MAIN 30 | int main() 31 | { 32 | struct Node *root = new Node(1); 33 | root->left = new Node(2); 34 | root->right = new Node(3); 35 | root->left->left = new Node(4); 36 | root->left->right = new Node(5); 37 | 38 | cout << "\nPostorder traversal of binary tree is \n"; 39 | printPostorder(root); 40 | 41 | return 0; 42 | } 43 | -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Post-Order Traversal/postorder.js: -------------------------------------------------------------------------------- 1 | // Prg for tree traversals in JS 2 | 3 | function Node(data) { 4 | this.data = data; 5 | this.left = null; 6 | this.right = null; 7 | } 8 | 9 | // Creating Nodes 10 | var root = new Node(1); 11 | var n1 = new Node(2); 12 | var n2 = new Node(3); 13 | var n3 = new Node(4); 14 | var n4 = new Node(5); 15 | 16 | // Setting Children 17 | root.left = n1; 18 | root.right = n2; 19 | n1.left = n3; 20 | n1.right = n4; 21 | 22 | 23 | // POSTORDER Traversal 24 | function post_order(root, nodes) { 25 | if (root && root.left) { 26 | post_order(root.left, nodes); 27 | } 28 | if (root && root.right) { 29 | post_order(root.right, nodes); 30 | } 31 | console.log(root.data); 32 | return nodes; 33 | } 34 | 35 | 36 | // MAIN 37 | console.log("PostOrder Traversal: ") 38 | post_order(root, []); -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Pre-Order Traversal/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Pre-Order Traversal/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Pre-Order Traversal/preorder.cpp: -------------------------------------------------------------------------------- 1 | // Prg for tree traversals in C++ 2 | #include 3 | using namespace std; 4 | 5 | // A class for a node 6 | struct Node 7 | { 8 | int data; 9 | struct Node *left, *right; 10 | Node(int data) 11 | { 12 | this->data = data; 13 | left = right = NULL; 14 | } 15 | }; 16 | 17 | // PREORDER Traversal 18 | void printPreorder(struct Node *node) 19 | { 20 | if (node == NULL) 21 | return; 22 | cout << node->data << " "; // print value 23 | printPreorder(node->left); // recur on left child 24 | printPreorder(node->right); // recur on right child 25 | } 26 | 27 | // MAIN 28 | int main() 29 | { 30 | struct Node *root = new Node(1); 31 | root->left = new Node(2); 32 | root->right = new Node(3); 33 | root->left->left = new Node(4); 34 | root->left->right = new Node(5); 35 | 36 | cout << "\nPreorder traversal of binary tree is \n"; 37 | printPreorder(root); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Pre-Order Traversal/preorder.js: -------------------------------------------------------------------------------- 1 | // Prg for tree traversals in JS 2 | 3 | function Node(data) { 4 | this.data = data; 5 | this.left = null; 6 | this.right = null; 7 | } 8 | 9 | // Creating Nodes 10 | var root = new Node(1); 11 | var n1 = new Node(2); 12 | var n2 = new Node(3); 13 | var n3 = new Node(4); 14 | var n4 = new Node(5); 15 | 16 | // Setting Children 17 | root.left = n1; 18 | root.right = n2; 19 | n1.left = n3; 20 | n1.right = n4; 21 | 22 | 23 | // PREORDER Traversal 24 | function pre_order(root, nodes) { 25 | console.log(root.data); 26 | if (root && root.left) { 27 | pre_order(root.left, nodes); 28 | } 29 | if (root && root.right) { 30 | pre_order(root.right, nodes); 31 | } 32 | return nodes; 33 | } 34 | 35 | 36 | // MAIN 37 | console.log("PreOrder Traversal: ") 38 | pre_order(root, []); 39 | -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Segment Tree/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Segment Tree/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Spanning Tree/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Spanning Tree/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Spanning Tree/Tree Traversal - Shortcut.lnk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Spanning Tree/Tree Traversal - Shortcut.lnk -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Sum of all leaf nodes/Sum of all leaf nodes of binary tree in C++.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | struct Node{ 6 | int data; 7 | Node *left, *right; 8 | }; 9 | 10 | Node *newNode(int data){ 11 | Node *temp = new Node(); 12 | temp->data = data; 13 | temp->left = temp->right = NULL; 14 | return temp; 15 | } 16 | 17 | void leafSum(Node *root, int *sum){ 18 | if (!root) 19 | return; 20 | 21 | if (!root->left && !root->right) 22 | *sum += root->data; 23 | leafSum(root->left, sum); 24 | leafSum(root->right, sum); 25 | } 26 | 27 | int main(){ 28 | 29 | Node *root = newNode(1); 30 | root->left = newNode(2); 31 | root->left->left = newNode(4); 32 | root->left->right = newNode(5); 33 | root->right = newNode(3); 34 | root->right->right = newNode(7); 35 | root->right->left = newNode(6); 36 | root->right->left->right = newNode(8); 37 | int sum = 0; 38 | leafSum(root, &sum); 39 | cout << sum << endl; 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/Trie/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/Trie/README.md -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/deleteTree/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fnplus/interview-techdev-guide/eaca1b6db4b27e9813aaec25a199b1baa4f9439b/Data Structures/Tree Traversal/deleteTree/.DS_Store -------------------------------------------------------------------------------- /Data Structures/Tree Traversal/deleteTree/cpp/delete a Tree.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | class node 6 | { 7 | public: 8 | int data; 9 | node* left; 10 | node* right; 11 | node(int data) 12 | { 13 | this->data = data; 14 | this->left = NULL; 15 | this->right = NULL; 16 | } 17 | }; 18 | 19 | 20 | void deleteTree(node* node) 21 | { 22 | if (node == NULL) return; 23 | 24 | deleteTree(node->left); 25 | deleteTree(node->right); 26 | 27 | cout << "\n Deleting node: " << node->data; 28 | free(node); 29 | } 30 | 31 | int main() 32 | { 33 | node *root = new node(1); 34 | root->left = new node(2); 35 | root->right = new node(3); 36 | root->left->left = new node(4); 37 | root->left->right = new node(5); 38 | 39 | deleteTree(root); 40 | root = NULL; 41 | 42 | cout << "\n Tree deleted "; 43 | 44 | return 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /Factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int c, n, fact = 1; 6 | 7 | printf("Enter a number to calculate its factorial\n"); 8 | scanf("%d", &n); 9 | 10 | for (c = 1; c <= n; c++) 11 | fact = fact * c; 12 | 13 | printf("Factorial of %d = %d\n", n, fact); 14 | 15 | return 0; 16 | } 17 | --------------------------------------------------------------------------------