├── .all-contributorsrc ├── .deepsource.toml ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug.md │ ├── documentation.md │ ├── feature.md │ ├── proposal.md │ └── question.md ├── auto_assigner_config.yml ├── issues_labeler.yml ├── labeler.yml ├── pull_request_template.md ├── stale.yml └── workflows │ ├── Auto_Issue_Closer.yml │ ├── Issue-assign.yml │ ├── Issue_watcher.yml │ ├── greetings.yml │ ├── issues_labeler.yml │ ├── java-format.yml │ ├── labeler.yml │ ├── reviewer_auto_assigner.yml │ └── stale.yml ├── .gitignore ├── C-Plus-Plus ├── BEST_PRACTICES_C-PLUS-PLUS.md ├── Bit--Manipulation │ ├── Brian_Kernighan's_Algorithm.cpp │ ├── Check_kth_bit_is_set_or_not.cpp │ ├── Count_no_of_set_bits.cpp │ ├── Find_duplicate_elements_using_XOR.cpp │ ├── Max_XOR_of_Two_Array.cpp │ ├── Minimum_XOR_Value.cpp │ ├── Non_Repeating_Integer.cpp │ ├── One_odd_occuring.cpp │ ├── Power_Set_Using_Bitwise.cpp │ ├── Power_of_2.cpp │ ├── Swap_even_and_odd_bits.cpp │ ├── Two_odd_occuring.cpp │ ├── all_possible_subset_of_a_set.cpp │ ├── no_of_bits_to_be_flipped_to_inter_convert_two_numbers.cpp │ ├── reverse_bits.cpp │ ├── rotate_bits.cpp │ └── sort_integers_by_their_number_of_set_bits.cpp ├── README.md ├── String_Algorithms │ └── KMP_Algorithm.cpp ├── blockchain │ └── README.md ├── computational_geometry │ ├── Check_Orientation_of_three_points.cpp │ ├── Convex_Hull_Graham_Scan.cpp │ ├── Convex_Hull_Jarvis_Algorithm.cpp │ ├── Klee's_Algorithm.cpp │ └── check_collinearity_of_three_points.cpp ├── cp │ ├── 1st_negative_no_in_every_window_of_size_k.cpp │ ├── 2-D_MatrixSorting.cpp │ ├── ARRAYSUB.cpp │ ├── Activity_Selection.cpp │ ├── Addition_of_2_numbers_representing_Linked_list.cpp │ ├── Array_Manipulation.cpp │ ├── Array_Right_Rotate.cpp │ ├── Balanced_array.cpp │ ├── Binary_Coded_String.cpp │ ├── Binary_Tree_Symmetric_or_not.cpp │ ├── Binary_Tree_to_Doubly_Linked_List.cpp │ ├── Build_wall.cpp │ ├── Check_for_Subsequence.cpp │ ├── Combination_Sum.cpp │ ├── Combination_sum_without_Repeated_values.cpp │ ├── Container_with_most_water.cpp │ ├── Continuous_Seq.cpp │ ├── Conversion_from_Binary_to_Decimal.cpp │ ├── Count_of_groups_having_largest_size.cpp │ ├── CountofPinS.cpp │ ├── Cyclically_rotate_of_array_by_one.cpp │ ├── Delete_without_head_pointer.cpp │ ├── DistinctElementsinaWindow.cpp │ ├── Dividing_tasks.cpp │ ├── Doubling_the_value.cpp │ ├── ElementsOccurrence_BinarySearch.cpp │ ├── EvenPairSum.cpp │ ├── Exactly_Four_Factors.cpp │ ├── Factorial_of_very_large_numbers.cpp │ ├── Find_transition_point.cpp │ ├── Four_Sum.cpp │ ├── Game_with_nos.cpp │ ├── Geek-onacci_Number.cpp │ ├── Generate_all_valid_parentheses_combinations.cpp │ ├── Generic_Swaps.cpp │ ├── Group_Anagrams.cpp │ ├── Intersection_Point_of_Y_shaped_LinkedList.cpp │ ├── Interval_list_Intersection.cpp │ ├── InversionCountProblem.cpp │ ├── Is_Valid_Sudoku.cpp │ ├── Josephus.cpp │ ├── Kadane_Algorithm.cpp │ ├── Knuth_Morris_Pratt.cpp │ ├── Lee_Algorithm.cpp │ ├── Leftmostnonrepeatingchar.cpp │ ├── Lexicographic_rank_of_string.cpp │ ├── Lexicographically_largest_palindrome_subsequence.cpp │ ├── Longest_substring_without_repeating_chars.cpp │ ├── LowestCommonAncestor_in_Tree.cpp │ ├── Max_Topology_short.cpp │ ├── Max_sum_in_the_configuration.cpp │ ├── Maximum_In_Array.cpp │ ├── Mean_after_removing_Kth_smallest_and_largest_elements.cpp │ ├── Meeting_Rooms.cpp │ ├── Merge_Intervals.cpp │ ├── Merge_string_alternatively.cpp │ ├── MinSwapToSortArray.cpp │ ├── Minimum_cost_of_ropes.cpp │ ├── Minimum_indexed_character.cpp │ ├── Minimum_number_to_form_the_sum_even.cpp │ ├── MosAlgo.cpp │ ├── Multiply_left_and_right_array_sum.cpp │ ├── NQueens.cpp │ ├── NextPermutation.cpp │ ├── Ones_and_Zeroes.cpp │ ├── Paint_Fence.cpp │ ├── Palindrome_number.cpp │ ├── Peak_element.cpp │ ├── Play_with_OR.cpp │ ├── Plucking_Flowers.cpp │ ├── Plus_One.cpp │ ├── Power_of_numbers.cpp │ ├── PrintAllSubsequences.cpp │ ├── Print_first_letter_of_every_word_in_the_string.cpp │ ├── Product_of_the_maximum_element_and_the_minimum_element_in_two_consecutive_arrays.cpp │ ├── Rainwaterharvesting.cpp │ ├── ReconstructOriginalDigitsFromEnglish.cpp │ ├── Reverse_Lookup_in_1D_array.cpp │ ├── Reverse_Words_in_String.cpp │ ├── Reverse_string_using_stack.cpp │ ├── Rotate_doubly_linked_list_by_given_node.cpp │ ├── Rotten_Oranges.cpp │ ├── Run_Length_Encoding.cpp │ ├── Search_target_element_in_Rotated_Sorted_Array.cpp │ ├── Sort_Color.cpp │ ├── Space_Array.cpp │ ├── Spiral_Matrix.cpp │ ├── String_to_int.cpp │ ├── SubArrayWithGivenSum.cpp │ ├── Subarray_of_length_two.cpp │ ├── SudukoSolver.cpp │ ├── Three_Sum.cpp │ ├── ToggleKthBitFromRight.cpp │ ├── Topological_sort.cpp │ ├── Tug_of_water.cpp │ ├── Two_Pointers_Method.cpp │ ├── Unique_number.cpp │ ├── Unique_prime_factors.cpp │ ├── ZeroSum.cpp │ ├── adjacent.cpp │ ├── aggressive_cows.cpp │ ├── all_possible_sums_using_fft.cpp │ ├── all_unique_permutation.cpp │ ├── baised_standings.cpp │ ├── busy_man.cpp │ ├── check_T_prime.cpp │ ├── check_anagrams.cpp │ ├── check_pangram.cpp │ ├── chopsticks.cpp │ ├── city.cpp │ ├── colouring_binary_tree.cpp │ ├── connecting_dots.cpp │ ├── construct_special_tree.cpp │ ├── count_leaves_in_binaryTree.cpp │ ├── count_occurences_of_anagrams.cpp │ ├── defend_kingdom.cpp │ ├── delete_peak_elements_in_maxHeap.cpp │ ├── find_first_and_last_position_index_of_a_number_in_array.cpp │ ├── find_no_of_digits_in_int.cpp │ ├── find_single_occuring_element.cpp │ ├── first1_binsearch.cpp │ ├── first_non_repeating_character.cpp │ ├── friends_pairing.cpp │ ├── generate_valid_parenthesis.cpp │ ├── graph_on_an_array.cpp │ ├── infix_to_postfix.cpp │ ├── integertobinarystring.cpp │ ├── largest_bst_in_btree.cpp │ ├── largest_subarray_of_sum_k.cpp │ ├── length_of_last_word.cpp │ ├── length_of_longest_substring_with_no_repeating_characters.cpp │ ├── long_factorials.cpp │ ├── longestCommonPrefix.cpp │ ├── longest_substring_with_k_unique_characters.cpp │ ├── matrix's_principal_secondary_diagonal_sum.cpp │ ├── matrix_min_operations_for_equal_sum.cpp │ ├── maxNumber.cpp │ ├── max_consecutive_ones.cpp │ ├── max_of_min_subarray.cpp │ ├── max_sum_increasing_subsequence.cpp │ ├── max_sum_subarray_of_size_k.cpp │ ├── maximum_of_all_subarray_of_size_k.cpp │ ├── maximum_pairwise_product.cpp │ ├── min_circles_to_be_removed.cpp │ ├── min_cost_to_construct_temple.cpp │ ├── min_cost_to_generate_n_cells.cpp │ ├── min_jobs.cpp │ ├── min_moves_knight_cannot_visited.cpp │ ├── minimum_spanning_tree.cpp │ ├── minimum_window_substring.cpp │ ├── next_greater_element.cpp │ ├── optimal_game.cpp │ ├── painter_partition.cpp │ ├── power.cpp │ ├── prefix_sum.cpp │ ├── prime_factors.cpp │ ├── printallcodes_recursion.cpp │ ├── product_of_array_except_itself.cpp │ ├── rain_water_trapping.cpp │ ├── ratInAMaze.cpp │ ├── recursion_string_permutation.cpp │ ├── removeMinParantheses.cpp │ ├── remove_cycle.cpp │ ├── remove_spaces_from_a_string.cpp │ ├── replace_each_node.cpp │ ├── replace_pi.cpp │ ├── reverseWords.cpp │ ├── robot_paths.cpp │ ├── rotate2darray.cpp │ ├── search_insert_position.cpp │ ├── snakes_and_ladders.cpp │ ├── sort_characters_by_their_occurrence.cpp │ ├── special_pairs.cpp │ ├── special_recursive_sequence.cpp │ ├── strange_hotel.cpp │ ├── target_sum_triplets.cpp │ ├── tkt_auction.cpp │ ├── total_more_child_vertices_than_parent.cpp │ ├── total_pairs_chosen.cpp │ ├── total_subtrees.cpp │ ├── weird algorithm.cpp │ ├── wines_problem.cpp │ └── zalgorithm.cpp ├── cryptography │ ├── Affine_substitution_Cipher.cpp │ ├── Caeser_Cipher.cpp │ ├── HillCipher.cpp │ ├── Homophonic_Cipher.cpp │ ├── KeywordCipher.cpp │ ├── Modified_Caeser_Cipher.cpp │ ├── PlayFair_Cipher.cpp │ ├── README.md │ ├── Rail_fence_Cipher.cpp │ ├── Shamir_Secret_Sharing.cpp │ ├── Simple_Columnar_Transposition.cpp │ ├── Simple_Columnar_Transposition_multiple_rounds.cpp │ ├── VernamCipher.cpp │ └── Vigenere_Cipher.cpp ├── dp │ ├── Arithmetic_Slices.cpp │ ├── BraillesDilemma.cpp │ ├── Catalan_DP.cpp │ ├── Coin_Change_Problem.cpp │ ├── Count_subset_given_difference.cpp │ ├── Egg_Dropping.cpp │ ├── Equal_sum_partition.cpp │ ├── House_Robber_Problem.cpp │ ├── Interleaving_strings.cpp │ ├── JobSchedulingWithMaxProfit.cpp │ ├── K-Tree.cpp │ ├── Kadane_Algorithm.cpp │ ├── Longest_bitonic_subsequence.cpp │ ├── Max_MatrixChain_Multiplication.cpp │ ├── Max_subarray_sum(DP).cpp │ ├── Max_subarray_sum_constant_space_DP.cpp │ ├── Maximum_ways_Coin_change_problem.cpp │ ├── Minimum_Insertion_Steps_to_make_Palindrome.cpp │ ├── Minimum_Sum_Partition_dp.cpp │ ├── Minimum_number_of_deletion.cpp │ ├── Palindrome_Partitioning.cpp │ ├── Print_Longest_Common_Subsequence.cpp │ ├── Printing_Shortest_Common_Supersequence.cpp │ ├── Rectangle_cutting.cpp │ ├── Rod_cutting_problem.cpp │ ├── Sprague_Grundy_Theorem.cpp │ ├── Staircase.cpp │ ├── Subset_sum.cpp │ ├── Tiling_2xN.cpp │ ├── Unique_BST.cpp │ ├── Zero_N_Knapsack.cpp │ ├── Zero_One_Knapsack.cpp │ ├── avg_submatrix_k.cpp │ ├── bellman_ford.cpp │ ├── coinTower.cpp │ ├── dijsktra.cpp │ ├── edit_distance.cpp │ ├── factorial_bottom_up.cpp │ ├── factorial_top_down.cpp │ ├── fibonacci_bottom_up.cpp │ ├── fibonacci_top_down.cpp │ ├── floyd_warshall.cpp │ ├── golomb_sequence.cpp │ ├── length_longest_decreasing_subsequence.cpp │ ├── longest_common_subsequence.cpp │ ├── longest_increasing_subsequence.cpp │ ├── longest_palin_subseq.cpp │ ├── maxSquareMatrixWithOnes.cpp │ ├── max_sum_rectangle.cpp │ ├── maximum_sum_decreasing_subsequence.cpp │ ├── maximum_sum_increasing_subsequence.cpp │ ├── min_ins_del.cpp │ ├── number_of_binary_trees.cpp │ ├── pascal's_triangle.cpp │ ├── shortest_common_superstring.cpp │ ├── shortest_uncommon_subseq.cpp │ ├── string_permutations.cpp │ ├── subsets_with_given_diff.cpp │ ├── townPlanning.cpp │ ├── travellingSalesman.cpp │ ├── unbounded_knapsack.cpp │ └── wildcard_matching.cpp ├── ds │ ├── AVL_Tree_or_not.cpp │ ├── Append_Last_N_To_First.cpp │ ├── Ascending_priority_queue.cpp │ ├── Auto_complete.cpp │ ├── BFS_Binary_Tree.cpp │ ├── BST_Range_Print.cpp │ ├── BST_from_Preorder_Traversal.cpp │ ├── BST_to_Greater_Sum_Tree.cpp │ ├── BSTtoMinHeap.cpp │ ├── Balanced_BST_From_a_vector_of_values.cpp │ ├── BinarySearchTree.cpp │ ├── BinaryTree.cpp │ ├── BinaryTreeFromInorderAndPreorder.cpp │ ├── BinaryTreeFromInorderPostorder.cpp │ ├── BinaryTreeUsingStack.cpp │ ├── BinaryTree_PreorderTraversal.cpp │ ├── Binary_Search_Tree_Validation.cpp │ ├── Binary_Tree_Kth_Smallest_Element.cpp │ ├── Binary_Tree_Max_Root_To_Leaf_Path_Sum.cpp │ ├── Binary_Tree_Print_All_Root_To_Leaf_Paths.cpp │ ├── Check_for_Binary_search_tree.cpp │ ├── CircularLinkedList.c │ ├── Circular_LinkedList.cpp │ ├── Circular_Queue.cpp │ ├── Common_Ancestors_Of_Nodes_Of_Binary_Tree.cpp │ ├── Construct_binary_tree_using_inorder_and_preorder.cpp │ ├── Descending_priority_queue.cpp │ ├── Detect_Cycle_In_LinkedList.cpp │ ├── Double_Ended_Queue.cpp │ ├── DoublyLinkedList.cpp │ ├── Find_first_and_last_positions_of_an_element_in_a_sorted_array.cpp │ ├── Floor_of_a_number_in_BST.cpp │ ├── Hashing_with_chaining.cpp │ ├── Height_Of_Binary_Tree_Non_Recursive.cpp │ ├── Inorder.cpp │ ├── Invert_Binary_Tree.cpp │ ├── K_Distance_Nodes_Binary_Tree.cpp │ ├── Leaf_Nodes_BST.cpp │ ├── LevelOrderTraversal.cpp │ ├── LinkedList.cpp │ ├── Linkedlisttree.cpp │ ├── Max_Leaf_To_Leaf_Path_Sum_Of_Binary_Tree.cpp │ ├── Max_Sum_Level_Of_Binary_Tree.cpp │ ├── Max_rectangle.cpp │ ├── Maximum_Element_of_Binary_Tree.cpp │ ├── Maximum_Width_BinaryTree.cpp │ ├── MergeSortLL.cpp │ ├── Merge_sorted_lists.cpp │ ├── Number_of_good_pairs.cpp │ ├── Priority_Queue.cpp │ ├── Priority_Queue_using_LinkedList.cpp │ ├── Quasi_Isomorphic_Binary_Trees.cpp │ ├── QueueLinkedList.cpp │ ├── Queue_all_operations_using_linkedlist.cpp │ ├── Queue_using_Stacks.cpp │ ├── RED-BLACK-TREE.cpp │ ├── Remove_all_Duplicates_from_Linkedlist.cpp │ ├── Reverse_LinkedList_Nodes_in_K-Groups.cpp │ ├── Reverse_Queue_content_using_Stack.cpp │ ├── Reverse_linked_list.cpp │ ├── RootToLeafSum.cpp │ ├── Row_with_max_1s.cpp │ ├── SLL_Operations_using_Unique_Key.cpp │ ├── Searching_in_BST.cpp │ ├── Shortest_Distance_Between_Nodes_Of_BST.cpp │ ├── Side_Views_of_Binary_tree.cpp │ ├── Sparse_Matrix_Representation.cpp │ ├── Stack_using_Array.cpp │ ├── Stack_using_LinkedList.cpp │ ├── Structurally_Identical_Binary_Trees.cpp │ ├── Sum_Of_Elements_Of_N_ary_Tree.cpp │ ├── Swapping_Nodes_of_Linked_list-Using_CPP.cpp │ ├── ThreadedBinaryTree.cpp │ ├── Tim_Sort.cpp │ ├── Trie_implementation.cpp │ ├── Vector.cpp │ ├── Vertical_Level_Sums_Of_Binary_Tree.cpp │ ├── Zig_Zag_Level_Order_Traversal_Binary_Tree.cpp │ ├── alternate_merging_of_linked_list.cpp │ ├── ancestors_of_given_number_BST.cpp │ ├── avl_tree.cpp │ ├── best_fit_memory.cpp │ ├── boundary_traversal_bst.cpp │ ├── detectionOfCycle_linkedList.cpp │ ├── double-hashing.cpp │ ├── first_fit.cpp │ ├── heap_sort.cpp │ ├── insertion_sort_on_linked_list.cpp │ ├── inverse_of_an_array.cpp │ ├── inversion_vector.cpp │ ├── iterative_inorder.cpp │ ├── iterative_postorder.cpp │ ├── iterative_preorder.cpp │ ├── kReverse_LinkedList.cpp │ ├── linear-probing.cpp │ ├── linked_list_middle_element.cpp │ ├── max_min_heap.cpp │ ├── palindrome_doubly_linked_list.cpp │ ├── postorder.cpp │ ├── prefix-to-postfix.cpp │ ├── preorder.cpp │ ├── prims_algo.cpp │ ├── priorityQ_array.cpp │ ├── quadratic-probing.cpp │ ├── queue.cpp │ ├── queue_using_circular_array.cpp │ ├── singly_linked_list.cpp │ ├── sort_list_of_0s_1s_2s.cpp │ ├── vertical_order_traversal_BinaryTree.cpp │ └── worst_fit_memory.cpp ├── graphs │ ├── 3Cycle.cpp │ ├── Adjacency_List.cpp │ ├── Articulation_points.cpp │ ├── BFS1.cpp │ ├── BellmanFord.cpp │ ├── Best_First_Search_Algorithm.cpp │ ├── Bidirectional_search_using_BFS_in_undirected_graph.cpp │ ├── Boruvka_algorithm_for_finding_MST.cpp │ ├── Bridges.cpp │ ├── Center_of_Star_Graph.cpp │ ├── Check_for_bipartite_graph.cpp │ ├── Connecting_Dots-Graphs_using_cpp.cpp │ ├── Depth_of_tree.cpp │ ├── DetectNegativeCycle.cpp │ ├── Diagonal_traversal.cpp │ ├── Diameter_of_binary_tree.cpp │ ├── Dijkstra_algorithm.cpp │ ├── DirectedCycleDetection.cpp │ ├── EdmondKarp.cpp │ ├── FloodFill.cpp │ ├── Iterative_dfs.cpp │ ├── Kosaraju_Algorithm.cpp │ ├── Largest_distance_between_2_nodes_in_a_tree.cpp │ ├── Postorder_Traversal.cpp │ ├── Preorder_Traversal.cpp │ ├── Prim_Algorithm.cpp │ ├── README.md │ ├── Tarjan's_Algorithm.cpp │ ├── TopologicalSort.cpp │ ├── Vertical_order_print_of_binary_tree.cpp │ ├── bfs.cpp │ ├── celebrity_problem.cpp │ ├── checkCycle_bfs.cpp │ ├── checkPath.cpp │ ├── detect_cycle.cpp │ ├── dfs_of_a_graph.cpp │ ├── inorder-traversal.cpp │ ├── is_it_a_tree.cpp │ ├── kahns_algorithm.cpp │ ├── kruskal_Algorithm.cpp │ ├── left_view_of_tree.cpp │ ├── min_and_max_in_BST.cpp │ ├── minimum_distance_using_SSSP_on_trees_by_DFS.cpp │ ├── number_of_connected_components.cpp │ ├── right_view_of_tree.cpp │ ├── shortest_path_using_bfs.cpp │ ├── subtree_size.cpp │ ├── top_view_binary_tree.cpp │ ├── topologicalSort_bfs.cpp │ └── zigzag_tree_traversal.cpp ├── heap │ ├── BSTtoMinHeap.cpp │ ├── ConnectNRopesWithMinumumCost.cpp │ ├── ConvertMinHeapToMax.cpp │ ├── K_Closest_Points_to_Origin.cpp │ ├── KthSmallestElement.cpp │ ├── Median_in_a_running_stream_of_integers.cpp │ ├── MergeKSortedList.cpp │ ├── Merge_k_sorted_arrays.cpp │ ├── Reconstruct_Itinerary.cpp │ ├── cheapest_flights_within_k_stops.cpp │ └── heap_implementation.cpp ├── math │ ├── Ackermann_function.cpp │ ├── Amicable_Pair.cpp │ ├── Binary_Exponentiation.cpp │ ├── Check_whether_a_number_is_power_of_2.cpp │ ├── Convert_decimal_to_binary.cpp │ ├── Difference_of_Two_Strings.cpp │ ├── Euler's_Totient_function.cpp │ ├── Extended_Euclidean_Algorithm.cpp │ ├── GCD_In_C.cpp │ ├── Hailstone_sequence.cpp │ ├── Hamming_Distance.cpp │ ├── Happy_Number.cpp │ ├── HarshadNumber.cpp │ ├── LucasSeries.cpp │ ├── Matrix_Chain_Multiplication.cpp │ ├── Matrix_rotation_90degree.cpp │ ├── Noble_Integer.cpp │ ├── Perfect_Number.cpp │ ├── Print_Palindrome_Partitions.cpp │ ├── Pronic_numbers.cpp │ ├── Pythagorean_Triples.cpp │ ├── Roman_To_Integer.cpp │ ├── Sieve_Of_Atkins.cpp │ ├── Sieve_of_Eratosthenes.cpp │ ├── Smallest_divisible_number.cpp │ ├── Squares_in_2n_Chessboard.cpp │ ├── Strong_Number.cpp │ ├── SumOf_TwoLarge_numbers_represented_as_strings.cpp │ ├── Sum_of_digits.cpp │ ├── Tower_Of_Hanoi.cpp │ ├── Word_break.cpp │ ├── armstrong_number.cpp │ ├── automorphic_number.cpp │ ├── binomial_coefficient_under_modulo.cpp │ ├── catalan_num.cpp │ ├── check_palindrome.cpp │ ├── counting_divisors_using_sieve_of_eratosthenes.cpp │ ├── decimal_to_hexadecimal.cpp │ ├── double_factorial.cpp │ ├── factorial_space_optimized.cpp │ ├── fibonacci.cpp │ ├── fibonacci_space_optimized.cpp │ ├── int_to_roman.cpp │ ├── krishnamurthy_number.cpp │ ├── magic_number.cpp │ ├── matrix_addition.cpp │ ├── matrix_multiplication.cpp │ ├── matrix_subtraction.cpp │ ├── matrix_transpose.cpp │ ├── modular_exponentiation.cpp │ ├── mystery_number.cpp │ ├── n_queen.cpp │ ├── neon_number.cpp │ ├── next_prime_number.cpp │ ├── number_of_digits.cpp │ ├── number_of_divisors.cpp │ ├── polynomial_addition.cpp │ ├── remove_invalid_parentheses.cpp │ ├── reorderedPowerOf2.cpp │ ├── reverse_a_number.cpp │ ├── smallest_prime_factor.cpp │ ├── special.cpp │ ├── sterns_diatomic_series.cpp │ ├── sudoku_solver.cpp │ ├── sum_of_divisors.cpp │ ├── tribonacci.cpp │ └── ugly_numbers.cpp ├── other │ ├── ActivitySelection.cpp │ ├── Add_two_binary_numbers.cpp │ ├── AllocateMinPages.cpp │ ├── Arranging_elements_of_array_to_form_biggestno.cpp │ ├── Calculate_max_sum_of_k_consecutive_elements.cpp │ ├── CarFueling.cpp │ ├── Common_Element_in_three_Sorted_array.cpp │ ├── Decimal_to_gray.cpp │ ├── DynamicHuffman.cpp │ ├── Fast_fibonacci_last_digit.cpp │ ├── Find_Common_Element_in_matrix.cpp │ ├── Find_Kth_smallest_element_in_sorted_Matrix.cpp │ ├── Find_array_is_Subset_of_another_array.cpp │ ├── Find_kth_Element_of_two_sorted_array.cpp │ ├── First_Missing_Positive_Number.cpp │ ├── Gray_Inverse_Code.cpp │ ├── IsomorphicStrings.cpp │ ├── Kth_largest_element.cpp │ ├── Kth_permutation_sequence.cpp │ ├── Kth_smallest_element.cpp │ ├── LargestNumber.cpp │ ├── Lazy_Propagation_in_Segment_Tree.cpp │ ├── Longest_Consecutive_Subsequence.cpp │ ├── Longest_subarray_with_equal_0_1.cpp │ ├── MEX_of_an_array.cpp │ ├── MaxNoOfConsecutive1'sFlipAtmostK0's.cpp │ ├── Max_in_BitonicArray.cpp │ ├── Maxm_consecutive_avgint_pairs.cpp │ ├── Median_in_row_wise_sorted_matrix.cpp │ ├── Median_of_two_Sorted_arrays_of_different_size.cpp │ ├── Median_of_two_Sorted_arrays_of_equal_size.cpp │ ├── MinJumpsToReachEndofArray.cpp │ ├── Minimum_Sum_Partition_recursion.cpp │ ├── Move_all_Negative_no_to_beginning_and_Positive_to_end.cpp │ ├── Pair-Star.cpp │ ├── Phone_keypad.cpp │ ├── Rabin_Karp_Algorithm_using_prefix_sum.cpp │ ├── Rabin_Karp_Algorithm_using_rolling_hash.cpp │ ├── Reverse_a_number_using_stack.cpp │ ├── Reversing_the_first_K_elements_of_a_Queue.cpp │ ├── Rotate_by_90.cpp │ ├── Rotate_by_one.cpp │ ├── RussianPeasant.cpp │ ├── RussianPeasantAlgo.cpp │ ├── SortColors-DutchNationalFlag.cpp │ ├── Sorting_an_array_of_zeroes_and_ones.cpp │ ├── Sum_of_divisors.cpp │ ├── SwapTwoNibbles.cpp │ ├── Transpose_Of_Square_Matrix.cpp │ ├── Triplet_sum_in_array.cpp │ ├── Union_and_Intersection_of_arrays.cpp │ ├── Unique_Number_III.cpp │ ├── addTwoLinkedLists.cpp │ ├── big_mod_algorithm.cpp │ ├── bulb_switch_1.cpp │ ├── bulb_switch_II.cpp │ ├── bulb_switch_III.cpp │ ├── bulb_switch_IV.cpp │ ├── check_set_clear_bit.cpp │ ├── count_of_set_bit_using_lookup_tech.cpp │ ├── distinct_subsets_of_set.cpp │ ├── divisors_of_natural_number.cpp │ ├── find_duplicate_elements_from_an_array.cpp │ ├── find_the_numbers.cpp │ ├── insert_usernames_in_database.cpp │ ├── job_sheduling_with_deadlines.cpp │ ├── knapsackfraction.cpp │ ├── kth_missing.cpp │ ├── lcm.cpp │ ├── majority_vote_algorithm.cpp │ ├── max_possible_subsequence.cpp │ ├── merge_2_sorted_arrays_without_extra_space.cpp │ ├── minimum_in_rotated_sorted_array.cpp │ ├── most_occurrence_strings.cpp │ ├── n_string_concatenate.cpp │ ├── odd_even_linked_list.cpp │ ├── palindrome_linked_list.cpp │ ├── remove_outermost_parenthesis.cpp │ ├── repeated_missing.cpp │ ├── string_rotation.cpp │ ├── string_scramble.cpp │ ├── subsets.cpp │ ├── subsets_iterative.cpp │ ├── sudoku_solver.cpp │ ├── trappingRainwater.cpp │ ├── vector_of_strings_occurs_more_than_one_time.cpp │ ├── whether_string_is_subsequence.cpp │ ├── zig-zag_array_sorted.cpp │ └── zig-zag_array_unsorted.cpp ├── search │ ├── Binary_Recursive_Search.cpp │ ├── Binary_Search.cpp │ ├── Interpolation_Search.cpp │ ├── Jump_Search.cpp │ ├── Linear_Search.cpp │ ├── Manacher's_Algorithm.cpp │ ├── Pair_Of_nodes_in_the_BST_which_Sum_to_S.cpp │ ├── README.md │ ├── Randomized_Select.cpp │ ├── Sqrt_Monotonic_Binary_Search.cpp │ ├── Staircase_Search.cpp │ ├── TernarySearch.cpp │ ├── Unbounded_Binary_Search.cpp │ ├── bilinear_search.cpp │ ├── exponential_search.cpp │ ├── fibonacci_search.cpp │ ├── orderAgnosticBS.cpp │ └── sublist_Search.cpp ├── sort │ ├── BST_Sort.cpp │ ├── Bead_Sort.cpp │ ├── Binary_Insertion_Sort.cpp │ ├── Bubble_Sort.cpp │ ├── Cocktail_shaker_sort.cpp │ ├── HeapSort.cpp │ ├── Merge_Sort.cpp │ ├── Quick_Sort.cpp │ ├── Quotient-Remainder_Sort.cpp │ ├── Randomized_Quick_Sort.cpp │ ├── Relative_Sort_Array.cpp │ ├── Shellsort.cpp │ ├── Single_loop_sort.cpp │ ├── Topological_Sort.cpp │ ├── Topological_Sorting_DFS.cpp │ ├── bucket_sort.cpp │ ├── circle_sort.cpp │ ├── comb_sort.cpp │ ├── counting_sort.cpp │ ├── countsort.cpp │ ├── in_place_merge_sort.cpp │ ├── insertion.cpp │ ├── merge_without_extra_space.cpp │ ├── pigeon_hole_sort.cpp │ ├── radix_sort.cpp │ ├── selection_sort.cpp │ ├── sleep_sort.cpp │ ├── stooge_sort.cpp │ ├── three_way_merge_sort.cpp │ ├── wave_sort.cpp │ └── wiggle_sort.cpp └── stack │ ├── CheckPalindrome.cpp │ ├── Check_for_balanced_parenthesis.cpp │ ├── Largest_rect_area_under_histogram.cpp │ ├── Previous_Greater_Element.cpp │ ├── Sort_stack_using_recursion.cpp │ ├── Stock_span_problem.cpp │ ├── clone_a_stack_without_using_extra_space.cpp │ ├── evaluate_postfix.cpp │ ├── infixToPostfix.cpp │ ├── maximum_size_of_balanced_bracket_sequence.cpp │ ├── nextGreatestToLeft.cpp │ ├── nextSmallestToLeft.cpp │ ├── nextSmallestToRight.cpp │ ├── next_greatest_right.cpp │ ├── palindromic_list.cpp │ ├── postfix_to_prefix.cpp │ ├── smallest_element_in_an_array.cpp │ ├── string_expression_evaluation_bodmas.cpp │ └── two_stacks_using_single_array.cpp ├── C-Sharp ├── README.md ├── blockchain │ └── README.md ├── cp │ ├── LengthOfLongestSubstring.cs │ └── README.md ├── cryptography │ ├── README.md │ └── vigenere_cipher.cs ├── dp │ ├── BinarySearchTree.cs │ ├── PartitionProblem.cs │ └── README.md ├── ds │ └── README.md ├── graphs │ ├── DFS.cs │ ├── IsTree.cs │ ├── Kosaraju's_algorithm_for_SCC.cs │ ├── README.md │ └── TopologicalSorting.cs ├── math │ ├── Armstrong_Number.cs │ ├── Catalan_Number.cs │ ├── Finding_no_of_digits_in_an_integer.cs │ ├── README.md │ └── tower_of_hanoi.cs ├── other │ ├── CountInversions.cs │ ├── Largest_Kth_Element.cs │ ├── README.md │ ├── Unique_Number_III.cs │ └── prime_factor_sieve.cs ├── search │ ├── BinarySearch.cs │ ├── Fibonacci_Search.cs │ ├── JumpSearch.cs │ ├── LinearSearch.cs │ ├── README.md │ └── RecursiveBinarySearch.cs └── sort │ ├── BubbleSort.cs │ ├── CountSort.cs │ ├── HeapSort.cs │ ├── InsertionSort.cs │ ├── MergeSort.cs │ ├── QuickSort.cs │ ├── README.md │ ├── RadixSort.cs │ └── SelectionSort.cs ├── C ├── Bit--Manipulation │ ├── count_num_of_set_bits.c │ ├── minimum_xor_value.c │ ├── no_of_bits_to_be_flipped_to_inter_convert_two_numbers.c │ ├── reverse_bits.c │ ├── rotate_bits.c │ └── toggle_kth_bit.c ├── C_Style_guide.md ├── README.md ├── blockchain │ └── README.md ├── computational_geometry │ └── check_collinearity_of_three_points.c ├── cp │ ├── Activity_selection.c │ ├── Adjacent_Element_Product.c │ ├── Array_Mirror_Inverse.c │ ├── Bitonic_subarray.c │ ├── BoyerMooreVote.c │ ├── Count_Distinct_Elements_in_Every_Window.c │ ├── Knutt_Morris_Prat.c │ ├── Lexicographic_rank.c │ ├── LuhnsAlgo.c │ ├── Maximum_Container_with_water.c │ ├── Median_of_two_sorted_arrays.c │ ├── README.md │ ├── Reverse_String_Recursion.c │ ├── Stock_Span.c │ ├── SudukoSolver.c │ ├── Trapping_rain_water.c │ ├── anagram_program.c │ ├── arrays_duplicate_elements.c │ ├── bigmod_algorithm.c │ ├── bulbSwitch.c │ ├── catalan_number.c │ ├── cp_sets_question.c │ ├── doublefactorial.c │ ├── first_missing_positive_integer.c │ ├── maxSubArraySum.c │ ├── max_consecutive_ones.c │ ├── max_sum_subarray.c │ ├── maximum_size_of_balanced_bracket_sequence.c │ ├── minimum_in_rotated_sorted_array.c │ ├── painter_partition.c │ ├── possible_code_recursion.c │ ├── prefix_sum.c │ ├── sum_of_triplet.c │ ├── two_pointers_method.c │ └── zalgorithm.c ├── cryptography │ ├── Affine_Substitution_Cipher.c │ ├── AutoKey_Cipher.c │ ├── Burrows_Wheeler_Transform.c │ ├── Columnar_Cipher.c │ ├── Hill_Cipher.c │ ├── Keyword_Cipher.c │ ├── MonoAlphabeticCipher.c │ ├── PlayFairCipher.c │ ├── README.md │ ├── Vernam_Cipher.c │ ├── Vigenere_Cipher.c │ ├── caesar_cipher.c │ └── railFenceCipher.c ├── dp │ ├── EditDistanceDP.c │ ├── Fibonacci.c │ ├── Max_Sub_SquareMatrixwithAll_1s.c │ ├── Max_Sum_Rectangle.c │ ├── N-Queen.c │ ├── README.md │ ├── Unique_BST.c │ ├── cutting_a_rod.c │ ├── floyd_warshal.c │ ├── golomb_sequence.c │ ├── houseRobber.c │ ├── length_longest_common_subsequence.c │ ├── length_longest_decreasing_subsequence.c │ ├── length_longest_increasing_subsequence.c │ ├── longest_common_substring.c │ ├── maximum_sum_decreasing_subsequence.c │ ├── maximum_sum_increasing_subsequence.c │ └── tiling_problem.c ├── ds │ ├── AVL_tree.c │ ├── Adjacency_matrix.c │ ├── AscendingPQ.c │ ├── BitonicPoint.c │ ├── CircularLinkedList.c │ ├── Circular_LL.c │ ├── DescendingPQ.c │ ├── Dijsktra.c │ ├── Double_Ended_Queue.c │ ├── EvaluationOfPostfixExpression.c │ ├── FenwickTree.c │ ├── FindBinaryTreeBst.c │ ├── FindLinkedListPalindrome.c │ ├── FindRouteBetwnTwoNode.c │ ├── Finding_a_pair_of_element.c │ ├── Hash_Table.c │ ├── Hashtable_chaining.c │ ├── Inorder.c │ ├── Iterative_inorder.c │ ├── Iterative_preorder.c │ ├── Leaf_Nodes_BST.c │ ├── List_deletenode_func.c │ ├── Merging_two_Linked_List.c │ ├── MinimumElemetInStack.c │ ├── Mirror_BinaryTree.c │ ├── Morris.c │ ├── Open_hashing.c │ ├── PairwiseSwap.c │ ├── Postorder.c │ ├── Preordertraversal.c │ ├── Priority_Queue_using_Linked_List.c │ ├── QueueImplementationWithList.c │ ├── Queueimplementation.c │ ├── README.md │ ├── Remove_Duplicate_In_Linked_List.c │ ├── SegregateOddEven.c │ ├── Sparse_Matrix.c │ ├── Spiral_Matrix.c │ ├── StackImplementationWithArray.c │ ├── StackImplementationWithLinkedList.c │ ├── StackUsingQueue.c │ ├── XOR.c │ ├── balanced_parenthesis.c │ ├── bellman_ford.c │ ├── best_fit_memory.c │ ├── binary_tree_from_preorder_and_inorder.c │ ├── circularqueue.c │ ├── detectLoopLL.c │ ├── doubly_linked_list.c │ ├── first_fit_memory.c │ ├── infixToPrefix.c │ ├── infix_to_postfix.c │ ├── infix_to_postfix.md │ ├── inorder_predecessor_successor.c │ ├── iterative_postorder.c │ ├── maxHeap.c │ ├── middle_element_of_linkedlist.c │ ├── minHeap.c │ ├── palindrome_doubly_linked_list.c │ ├── paranchecker.c │ ├── postfixToInfix.c │ ├── postfix_to_prefix.c │ ├── prefix-to-postfix.c │ ├── queue_all_functionality.c │ ├── queue_using_circular_array.c │ ├── rabin_karp_algo.c │ ├── removeDuplicate.c │ ├── reverse-queue.c │ ├── reverseWordsOfString.c │ ├── reverse_linked_list.c │ ├── singly_linked_list.c │ ├── stack_sort.c │ └── worst_fit_memory.c ├── graphs │ ├── Adjacency_List.c │ ├── BFS.c │ ├── DFS.c │ ├── Kruskal_Algorithm.c │ ├── Prim_Algorithm.c │ ├── README.md │ ├── celebrity_problem.c │ ├── minimum_distance_using_SSSP_on_trees_by_DFS.c │ ├── number_of_connected_components.c │ └── warshall.c ├── math │ ├── Binary_Exponentiation.c │ ├── Check_whether_a_number_is_power_of_2.c │ ├── DecimalToBinary.c │ ├── Decimal_to_Hex.c │ ├── Euler's_Totient_function.c │ ├── Extended_Euclidean_Algorithm.c │ ├── GCD_In_C.c │ ├── Kaprekar_no.c │ ├── Magic_Number.c │ ├── Neon_number.c │ ├── Noble_Integer.c │ ├── Palindrome.c │ ├── Pascals_triangle.c │ ├── Pronic_numbers.c │ ├── Quadratic_Equation.c │ ├── README.md │ ├── Sieve_of_Eratosthenes.c │ ├── armstrong_number.c │ ├── automorphic_no.c │ ├── binary_to_decimal.c │ ├── factorial.c │ ├── happy_number.c │ ├── krishnamurthy_number.c │ ├── lowest_prime_factor_of_number.c │ ├── lucas_number.c │ ├── matrix_addition.c │ ├── matrix_multiplication.c │ ├── matrix_subtraction.c │ ├── matrix_symmetric.c │ ├── matrix_transpose.c │ ├── mystery_number.c │ ├── number_of_digits.c │ ├── number_of_divisors.c │ ├── perfect_number.c │ ├── polynomial_addition.c │ ├── polynomial_multiplication.c │ ├── reverse_number.c │ ├── special.c │ ├── sterns_diatomic_series.c │ ├── strong_number.c │ ├── sum_of_digits.c │ ├── sum_of_divisors.c │ └── tribonacci.c ├── operating_system │ ├── Round_Robin_Scheduling.c │ ├── bankers.c │ ├── first_come_first_serve_algorithm.c │ └── priority_sjf.c ├── other │ ├── Find_the_numbers.c │ ├── MEX_of_an_array.c │ ├── Maximum_Product_Subarray.c │ ├── Number_of_duplicates_using_Binary_search.c │ ├── Palindrome.c │ ├── README.md │ ├── Russian_Peasant_Algorithm.c │ ├── String_Palindrome_or_not.c │ ├── SudokuSolver.c │ ├── Swap_two_nibbles.c │ ├── Tower_Of_Hanoi.c │ ├── Union_and_Intersection_of_two_Sorted_arrays.c │ ├── UniqueNumberIII.c │ ├── check_for_subsequence.c │ ├── concatenate_two_strings.c │ ├── find_first_and_last_position_index_of_a_number_in_array.c │ ├── leftmost_nonrepeating_char.c │ ├── recursion_string.c │ ├── remove_outermost_parentheses.c │ ├── ugly_number.c │ └── window_sliding_technique.c ├── search │ ├── Binary_search.c │ ├── Fibonacci_Search.c │ ├── Interpolation.c │ ├── IterativeBinarySearch.c │ ├── JumpSearch.c │ ├── Manacher's_Algorithm.c │ ├── README.md │ ├── Staircase_Search.c │ ├── linear_search.c │ ├── random_search.c │ └── randomized_selection_algorithm.c ├── sort │ ├── BST_Sort.c │ ├── Count_Inversions.c │ ├── GnomeSort.c │ ├── HeapSort.c │ ├── InsertionSort.c │ ├── Iterative_Merge_Sort.c │ ├── MAX_MIN_HeapSort.c │ ├── MatrixSorting.c │ ├── MergeSort.c │ ├── OPtimizBubble_Sort.c │ ├── README.md │ ├── ShellSort.c │ ├── Wiggle_sort.c │ ├── beadSort.c │ ├── bubble_sort.c │ ├── bucketSort.c │ ├── circle_sort.c │ ├── comb.c │ ├── countingSort.c │ ├── mergesort_in_O(1)_space_complexity.c │ ├── oddevensort.c │ ├── pigeon_hole_sort.c │ ├── quickSort.c │ ├── radix_sort.c │ ├── selection_sort.c │ ├── shaker_sort.c │ ├── stooge_sort.c │ ├── three_way_merge_sort.c │ └── tim_sort.c └── stack │ └── Infix_to_Postfix.c ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── Dart ├── Array │ ├── Floor_of_sorted_array.dart │ ├── Geometric_Progression.dart │ ├── K_Largest_Element_Array.dart │ ├── MEX_array.dart │ ├── Missing_in_AP.dart │ ├── Palindrome_array.dart │ ├── Remove_duplicates_from_array.dart │ ├── Reverse_array_in_groups.dart │ ├── Segregate_even_odd.dart │ ├── Sort_array_wave_form.dart │ └── Subarray_Sum.dart ├── README.md ├── cryptography │ ├── AffineCipher.dart │ ├── CaesarCipher.dart │ └── VernamCipher.dart ├── dp │ ├── GolombSequence.dart │ ├── RodCuttingProblem.dart │ └── StringPermutations.dart ├── maths │ ├── Ackermann_function.dart │ ├── Areas2D.dart │ ├── Armstrong.dart │ ├── ArmstrongRecursive.dart │ ├── Binary_Exponentiation.dart │ ├── DecimalToBinary.dart │ ├── DisariumNumber.dart │ ├── Euclidean_Algorithm_to_find_GCD.dart │ ├── Euler's_Totient_function.dart │ ├── Factorial.dart │ ├── HappyNumber.dart │ ├── HarshadNumber.dart │ ├── Largest_Prime_Factor.dart │ ├── MagicNumber.dart │ ├── Modular_multiplicative_inverse.dart │ ├── MysteryNumber.dart │ ├── NeonNumber.dart │ ├── PerfectNumber.dart │ ├── PronicNumber.dart │ ├── Squareroot_binary_search.dart │ ├── StrongNumber.dart │ ├── SumOfDigits.dart │ ├── TowerOfHanoi.dart │ ├── TrimorphicNumber.dart │ ├── UglyNumber.dart │ ├── automorphic_number.dart │ ├── binomial_coefficient_under_modulo.dart │ ├── catalan_number.dart │ ├── check_palindrome.dart │ ├── decimal_to_hexadecimal.dart │ └── double_factorial.dart ├── search │ ├── Bilinear_Search.dart │ ├── BinarySearch.dart │ ├── FibonacciSearch.dart │ ├── InterpolationSearch.dart │ ├── Jump_Search.dart │ ├── LinearSearch.dart │ └── Sentinel_Search.dart └── sort │ ├── BeadSort.dart │ ├── BubbleSort.dart │ ├── BucketSort.dart │ ├── Cocktail_Sort.dart │ ├── Counting_Sort.dart │ ├── Heap_Sort.dart │ ├── InsertionSort.dart │ ├── Merge_Sort.dart │ ├── Quick_Sort.dart │ ├── Radix_Sort.dart │ ├── Selection_sort.dart │ ├── Shell_Sort.dart │ ├── Stooge_Sort.dart │ └── Tim_Sort.dart ├── Go ├── README.md ├── cp │ └── target_sum_triplets │ │ └── target_sum_triplets.go ├── cryptography │ ├── Affine_Substitution_Cipher │ │ └── affinecipher.go │ ├── Burrows_Wheeler_Transform │ │ └── Burrows_Wheeler_Transform.go │ ├── Caesar_Cipher │ │ └── Caesar_Cipher.go │ ├── Columnar_Cipher │ │ └── Columnar_Cipher.go │ ├── Hill_Cipher │ │ └── Hill_Cipher.go │ ├── Keyword_Cipher │ │ └── Keyword_Cipher.go │ ├── Monoalphabetic_Cipher │ │ └── monoalphabeticcipher.go │ ├── PlayFair_Cipher │ │ └── playfaircipher.go │ ├── RailFence_Cipher │ │ └── railfencecipher.go │ ├── Vernam_Cipher │ │ └── Vernam_Cipher.go │ └── Vigenere_Cipher │ │ └── Vigenere_Cipher.go ├── dp │ ├── Max_SubArray_Sum │ │ └── Max_SubArray_Sum.go │ ├── coin_change │ │ └── coin_change_problem.go │ ├── factorial │ │ └── factorial.go │ ├── fibonacci │ │ └── fibonacci.go │ ├── golomb_sequence │ │ └── golomb_sequence.go │ ├── longest_common_subsequence │ │ └── longest_common_subsequence.go │ ├── longest_substring │ │ └── longest_substring.go │ └── stack │ │ └── stack.go ├── ds │ ├── binary_tree │ │ ├── inorder_traversal_binary_tree │ │ │ └── inorder_traversal_binarytree.go │ │ ├── post_order_traversal │ │ │ └── Post_Order_Traversal.go │ │ └── pre_order_traversal │ │ │ └── Pre_Order_Traversal.go │ ├── linked_list │ │ ├── singly_linked_list │ │ │ └── singly_linked_list.go │ │ └── singly_linked_list_reversed │ │ │ └── singly_linked_list_reversed.go │ ├── queue │ │ └── queue_using_stack │ │ │ └── queue_using_stack.go │ └── stack │ │ ├── Stack.go │ │ └── stack_using_queue │ │ └── stack_using_queue.go ├── graphs │ └── topological_sort │ │ └── topological_sort.go ├── math │ ├── Armstrong_Number │ │ └── armstrongnumber.go │ ├── Automorphic_Number │ │ └── automorphicnumber.go │ ├── Binary │ │ └── checkisnumberpoweroftwo.go │ ├── Catalan_Number │ │ └── catalannumber.go │ ├── Decimal_to_Binary │ │ └── dectobin.go │ ├── Fibonacci │ │ └── fibonacci.go │ ├── GCD │ │ └── GCD.go │ ├── Happy_Number │ │ └── happynumber.go │ ├── Kaprekar_Number │ │ └── kaprekarnumber.go │ ├── Lucky_Number │ │ └── Lucky_Number.go │ ├── Magic_Number │ │ └── Magic_Number.go │ ├── Modular_Exponentiation │ │ └── modexp.go │ ├── Mystery_Number │ │ └── Mystery_Number.go │ ├── Neon_Number │ │ └── neonnumber.go │ ├── Noble_Integer │ │ └── nobleinteger.go │ ├── Palindrome │ │ └── palindrome.go │ ├── Perfect_Number │ │ └── Perfect_Number.go │ ├── Prime_Number │ │ └── Prime_Number.go │ ├── README.md │ ├── Strong_Number │ │ └── strongnumber.go │ ├── Sum_of_digits │ │ └── sumofdigitsofnumber.go │ ├── Ugly_Number │ │ └── uglynumber.go │ ├── areas │ │ ├── 2D │ │ │ └── Areas2D.go │ │ └── 3D │ │ │ └── Areas3D.go │ ├── armstrong_number │ │ └── armstrong_number.go │ ├── factorial │ │ └── factorial.go │ ├── integer_to_roman │ │ └── IntegerToRoman.go │ ├── karatsuba_multiplication │ │ └── karatsuba_multiplication.go │ └── sieve_of_eratosthenes │ │ └── sieve_of_eratosthenes.go ├── other │ └── tower_of_hanoi │ │ └── Tower_of_Hanoi.go ├── search │ ├── Binary_Recursive_Search │ │ └── BinarySearchRecursive.go │ ├── Fibonacci_search │ │ └── fibonacci_search.go │ ├── Jump_Search │ │ └── JumpSearch.go │ ├── binary_search │ │ └── binary_search.go │ ├── exponential_search │ │ └── exponentialsearch.go │ ├── interpolation_search │ │ └── interpolation_search.go │ ├── linear_search │ │ └── linear_search.go │ └── linera_search_recursive │ │ └── linearsearch_recursive.go └── sort │ ├── bubble_sort │ └── bubbleSort.go │ ├── counting_sort │ └── countingSort.go │ ├── insertion_sort │ └── insertionSort.go │ ├── merge_parallel_sort │ └── merge_sort_parallel.go │ ├── merge_sequential_sort │ └── merge_sort_sequential.go │ ├── merge_sort │ └── mergeSort.go │ ├── quick_sort │ └── quickSort.go │ ├── radix_sort │ └── radixSort.go │ ├── selection_sort │ └── selectionSort.go │ └── shell_sort │ └── shell_sort.go ├── Java ├── Algorithms │ ├── Min_Max_Algorithm_implementation.java │ ├── Moore_Algorithm.java │ ├── RussianPeasant.java │ ├── Sieve_of_Eratosthenes.java │ ├── Strassens_Algo_for_Matrix_multiplication.java │ ├── Two_pointer_Algorithm.java │ ├── ZAlgorithm.java │ ├── bigmod_algorithm.java │ └── kadanes_Java.java ├── Greedy_Algorithms │ ├── Active_Selection.java │ ├── Dijsktra.java │ ├── FractionalKnapsack.java │ └── Job_Scheduling.java ├── Operating-System │ ├── CPU_Scheduling_FCFS.java │ ├── CPU_Scheduling_RR.java │ ├── CPU_Scheduling_SJF.java │ ├── CPU_Scheduling_SRTF.java │ ├── MainDisc.java │ ├── alloc.java │ ├── allocate.java │ └── banker.java ├── README.md ├── blockchain │ └── README.md ├── cp │ ├── AggressiveCows.java │ ├── Anagram.java │ ├── ArmStrongRecursion.java │ ├── BFS_RottenOranges.java │ ├── BalancedParenthesis.java │ ├── CheckForSubSequence.java │ ├── CountAnagrams.java │ ├── Count_The_Reversals.java │ ├── Count_Words.java │ ├── Crossword_puzzle.java │ ├── Defanged_IPv4.java │ ├── Distinct_Element.java │ ├── Duplicate_word.java │ ├── DutchFlag.java │ ├── Factorial_large_numbers.java │ ├── FirstNegativeNumber.java │ ├── HappinessProblem.java │ ├── Identical_Words.java │ ├── Intersection_of_Two_Arrays.java │ ├── Jump_Game.java │ ├── KMP_Algorithm.java │ ├── Kth_largest_element_in_array.java │ ├── LongestSubarraySum.java │ ├── LongestSubstringDistinctChar.java │ ├── LongestSubstringNoRepeatingChar.java │ ├── LongestSubstring_without_repeating_characters.java │ ├── Longest_Common_Prefix.java │ ├── Longest_Pallindromicsubstring.java │ ├── MEX_of_an_array.java │ ├── Main.java │ ├── MatrixRotation.java │ ├── MaximumEachSubarray.java │ ├── MaximumOfMinimumSubarrays.java │ ├── MaximumSumSubarray.java │ ├── Maximum_Function.java │ ├── Median_of_two_sorted_arrays.java │ ├── Meetings.java │ ├── MergeOverlappingArray.java │ ├── Min_Element_Rotated_array.java │ ├── MinimumWindowSubstring.java │ ├── NQueens.java │ ├── N_Queens_Problem_Efficient.java │ ├── NextSmallestToRight.java │ ├── Next_Greater_Element.java │ ├── Paint_Fence.java │ ├── Prime.java │ ├── PrimeRecursion.java │ ├── Prime_range.java │ ├── Queue_using_Stack.java │ ├── README.md │ ├── Rabin_Karp.java │ ├── RatInAMaze.java │ ├── RectArea.java │ ├── RemoveDuplicateElement.java │ ├── RemoveDuplicateElementWithoutExtraSpace.java │ ├── Remove_Outermost_parentheses.java │ ├── ReverseString.java │ ├── Reverse_words_in_String.java │ ├── Run_Length_Encoding.java │ ├── Shortest_Dist.java │ ├── Sort_2D_Array.java │ ├── Spiral_Matrix.java │ ├── Stack_using_Queue.java │ ├── Staircase_problem.java │ ├── StockSpan.java │ ├── String_to_int.java │ ├── Subarray.java │ ├── SubarraySumZero.java │ ├── SudukoSolver.java │ ├── Trapping_rain_water.java │ ├── Trapping_rain_water_2D.java │ ├── UglyRecursion.java │ ├── Zig_Zag.java │ ├── minimum_in_rotated_sorted_array.java │ ├── nextGreaterElementLeft.java │ ├── nextSmallestToLeft.java │ ├── prefix_sum.java │ ├── remove_element_from_array.java │ ├── slding_window_technique.java │ └── target_sum_triplets.java ├── cryptography │ ├── AffineCipher.java │ ├── HillCipher.java │ ├── HomophonicCipher.java │ ├── KeyWord.java │ ├── ModifiedCaesarCipher.java │ ├── PlayFairCipher.java │ ├── RailFenceCipher.java │ ├── SimpleColumnarTranspositionCipher.java │ ├── SimpleColumnarTranspositionWithMultipleRoundsCipher.java │ ├── VigenereCipher.java │ ├── XORCipher.java │ ├── caeserCipher.java │ └── vernamCipher.java ├── dp │ ├── BinarySearchTreeCount.java │ ├── Climb_Stairs_With_Minimum_Moves.java │ ├── CoinChangeUsingDp.java │ ├── Coin_Change.java │ ├── EggDroppingProblem.java │ ├── Finding_shortest_path_for_multistaged_graph.java │ ├── FlightOfStairs.java │ ├── JobSequencingToMaximizeProfit.java │ ├── KOrderedLCS.java │ ├── Kadane_Algorithm.java │ ├── Knapsack_01.java │ ├── LCS.java │ ├── LCSThreeStrings.java │ ├── Longest_bitonic_subsequence.java │ ├── Make_string_palindrome_using_DP.java │ ├── MaximumSumRectangle.java │ ├── MemoryAllocations.java │ ├── MinimumCostPath.java │ ├── Optimal_Binary_Search_tree_using_DP.java │ ├── Painting_fence.java │ ├── README.md │ ├── Rectangle_cutting.java │ ├── RightViewBT.java │ ├── Rod_Cutting.java │ ├── SubsetSumToTarget.java │ ├── Traveling_SalesmanDP.java │ ├── Unique_BST.java │ ├── equalSumPartition.java │ ├── flood_fill.java │ └── shortestSupersequence.java ├── ds │ ├── AVL_Tree.java │ ├── Bestfit.java │ ├── Binary_Tree.java │ ├── Build_Expression_Tree.java │ ├── CheckBST.java │ ├── CircularQueue.java │ ├── DEQueue.java │ ├── DeleteElementLL.java │ ├── DetectLoopLL.java │ ├── Diameter_Of_A_BinaryTree.java │ ├── Hashtable_chaining.java │ ├── Hashtable_linear_probing.java │ ├── Huffman.java │ ├── Infix_to_Postfix.java │ ├── IntersectionPointOfLL.java │ ├── LCAofaBST.java │ ├── LevelOrderTraversalRecursion.java │ ├── MatrixSorting.java │ ├── MedianOfSortedArrays.java │ ├── MergeInBetweenLinkedLists.java │ ├── MergeSortedArrays.java │ ├── MiddleOfLinkedList.java │ ├── Min_Element_In_Stack.java │ ├── NodetoRootPath.java │ ├── Prefix_to_postfix.java │ ├── PriorityQueueEg.java │ ├── Queue.md │ ├── QueueandStack.java │ ├── Queuell.java │ ├── README.md │ ├── RemDupInLLWithoutExtraSpace.java │ ├── Reverse_alternate_k_Nodes.java │ ├── Reverse_queue_using_stack.java │ ├── ReversingCircularLinkedList.java │ ├── SegmentTree.java │ ├── SparseMatrices.java │ ├── SparseMatrix.java │ ├── Stack.java │ ├── Stack.md │ ├── StackUsingArrays.java │ ├── StackUsingQueue.java │ ├── Stackll.java │ ├── Top_view_of_binary_tree.java │ ├── Trie_with_Hashmap.java │ ├── ZigZag_Traversal_Trees.java │ ├── balancedBrackets.java │ ├── foldALinkedList.java │ ├── heapmain.java │ ├── linkedList.java │ ├── linkedListReverse.java │ ├── postorder_Traversal.java │ ├── preOrderTraversal.java │ └── queue.java ├── graphs │ ├── Articulation_Point.java │ ├── BFS.java │ ├── BipartiteCheck.java │ ├── DFS.java │ ├── Dijkstra.java │ ├── DirectedCycleDetection.java │ ├── Floyd_Warshall_Algorithm.java │ ├── Kruskal_Algorithm.java │ ├── LaplacianMatrix.java │ ├── LevelOrderTraversalInQueue.java │ ├── Paths_From_Source_To_Destination.java │ ├── Prim_Algorithm.java │ ├── README.md │ ├── TopologicalSort.java │ └── left_view_binary_tree.java ├── math │ ├── Amicable_Pair.java │ ├── ArmStrongRecursion.java │ ├── ArmstrongNumber.java │ ├── AsciiOfString.java │ ├── Big_Integer_Factorial.java │ ├── Binary_Exponentiation.java │ ├── CatalanNumber.java │ ├── Complex.java │ ├── DoubleFactorial.java │ ├── Euler's_Totient_function.java │ ├── ExtendedEuclidAlgo.java │ ├── Factorial.java │ ├── FactorialUsingBigInteger.java │ ├── Findmedian.java │ ├── HCFOfTwoNumber.java │ ├── HappyNumber.java │ ├── LuckyNumber.java │ ├── Magicnumber.java │ ├── Matrix_Transpose.java │ ├── Matrix_addition.java │ ├── Matrix_multiplication.java │ ├── MysteryNumber.java │ ├── Neon_number.java │ ├── PalindromeRecursion.java │ ├── PascalNthRowSum.java │ ├── Perfect_Number.java │ ├── Quadratic_Equation.java │ ├── README.md │ ├── Segmented_Sieve.java │ ├── SieveOfEratosthenes.java │ ├── Special.java │ ├── Squares_in_2n_Chessboard.java │ ├── SumOfDigit.java │ ├── check_strong_number.java │ ├── check_whether_a_number_is_power_of_2.java │ ├── countDigits │ │ ├── iterative.java │ │ ├── recursive.java │ │ └── stringmethod.java │ ├── cullen_number.java │ ├── good_number.java │ ├── lucastheorem.java │ ├── number_of_divisors.java │ ├── polynomial.java │ ├── sieveOfAtkin.java │ ├── smallest_prime_factor.java │ ├── sum_of_divisors.java │ └── tribonacci.java ├── other │ ├── 3sum_closest_to_target.java │ ├── AdjacentElementProduct.java │ ├── ArrayProductExceptSelf.java │ ├── BlockedMaze.java │ ├── CountCompleteTreeNode.java │ ├── FindGCDOfTwoNo.java │ ├── FindNumbers.java │ ├── FirstMissingPositiveNumber.java │ ├── FirstNonRepeatingChar.java │ ├── GenerateParentheses.java │ ├── InfixToPostfix.java │ ├── InfixtoPrefix.java │ ├── InsertPosition.java │ ├── Is_symmetric_tree.java │ ├── Key_n_room.java │ ├── KeypadSequence.java │ ├── KnightsTour.java │ ├── LastDigitFibonacci.java │ ├── LetterCodeRecursion.java │ ├── Longest_Consecutive_Squence.java │ ├── MaximumSquareMatrix.java │ ├── MergeSortedArrays.java │ ├── MinimumDepthBT.java │ ├── MinimumSumPartition.java │ ├── NKnightKill.java │ ├── OnePlustoWhole.java │ ├── Optimal_division_of_numbers.java │ ├── PainterPartition.java │ ├── Pair_programmers_productivity_problem.java │ ├── Pairwise_bitdiff_sum.java │ ├── Palindrome.java │ ├── Peak_element.java │ ├── README.md │ ├── RainWaterHarvesting.java │ ├── RecursionCount.java │ ├── Repeating_and_missing_number.java │ ├── RetrieveBTS.java │ ├── Search_insert_index.java │ ├── SetBitsInInteger.java │ ├── SortedArrayToBST.java │ ├── SubSequences.java │ ├── SudokuSolver.java │ ├── SumOfLeftLeaves.java │ ├── SumRootToLeaf.java │ ├── SwapNibbles.java │ ├── TowerOfHanoi.java │ ├── Trimming_binary_tree.java │ ├── UnionUnsortedArray.java │ ├── UniqueIII.java │ ├── UniqueNumberBitmasking.java │ ├── WordLadder.java │ ├── linearProbing.java │ ├── max_consecutive_ones.java │ ├── quadraticProbing.java │ ├── remove_element_from_array.java │ ├── smallest_and_longest_SubString.java │ └── three_Sum_problem.java ├── search │ ├── Bilinear_Search.java │ ├── BinarySearchRecursive.java │ ├── Binary_search.java │ ├── Exponential_search.java │ ├── Fibonacci_search.java │ ├── Interpolation_search.java │ ├── Linear_search.java │ ├── ManacherAlgorithm.java │ ├── README.md │ ├── Stack_Search.java │ ├── TernarySearch.java │ └── jumpSearch.java └── sort │ ├── BeadSort.java │ ├── BubbleSort.java │ ├── BucketSort.java │ ├── CocktailSort.java │ ├── CombSort_implementation.java │ ├── CountingSort.java │ ├── HeapSort.java │ ├── InsertionSort.java │ ├── LomutoPartition.java │ ├── MergeSortRecursion.java │ ├── Merge_sort.java │ ├── MinimumSwapsForNIntegers.java │ ├── OptimizedBubbleSort.java │ ├── PancakeSort.java │ ├── QuickSort.java │ ├── README.md │ ├── RadixSort.java │ ├── SelectionSort.java │ ├── ShellSort.java │ ├── SleepSort.java │ ├── TreeSort.java │ └── quicksort_in_strings.java ├── JavaScript ├── Algorithms │ ├── Armstrong.js │ ├── BoyerMooreAlgorithm.js │ ├── LongestIncreasingSubsequenceDP.js │ ├── RussianPeasant.js │ ├── ZAlgorithm.js │ └── kadane's_algo.js ├── Backtracking │ └── N-Queens.js ├── ML │ └── NeuralNetwork.js ├── README.md ├── blockchain │ └── README.md ├── cp │ ├── BackspaceCompare.js │ ├── CountAnagrams.js │ ├── FirstNegativeIntegerInEveryWindowOfSizeK.js │ ├── Median_of_two_sorted_arrays.js │ ├── README.md │ ├── ReverseString.js │ ├── SlidingWindowMaximum.js │ ├── TwoSum.js │ └── WaterContainer.js ├── cryptography │ └── README.md ├── dp │ ├── Climbing_stairs.js │ ├── Painting_fence.js │ ├── README.md │ └── flightOfStairs.js ├── ds │ ├── AVLTree.js │ ├── CircularSinglyLinkedList.js │ ├── DoublyLinkedList.js │ ├── DynamicLinkedList.js │ ├── Hash.js │ ├── Iterative_inorder.js │ ├── Iterative_postorder.js │ ├── Iterative_preorder.js │ ├── LinkedList.js │ ├── Parenthesis_Checker.js │ ├── Queue.js │ ├── QueueLinkedList.js │ ├── QueueStack.js │ ├── README.md │ ├── RadixSort.js │ ├── Recursive_postorder.js │ ├── Stack.js │ ├── StackLinkedList.js │ ├── ValidParentheses.js │ ├── bestfit.js │ ├── firstfit.js │ ├── infixevaluator.js │ ├── infixtopostfix.js │ ├── infixtoprefix.js │ ├── postfixevaluator.js │ ├── prefixevaluator.js │ ├── recursive_preorder.js │ └── worstfit.js ├── graphs │ └── README.md ├── math │ ├── ArmstrongNumbers.js │ ├── CountDigits_Integer.js │ ├── DoubleFactorial.js │ ├── Fibonacci.js │ ├── HappyNumber.js │ ├── Matrix_addition.js │ ├── Matrix_multiplication.js │ ├── Matrix_transpose.js │ ├── NeonNumber.js │ ├── Palindrome_checker.js │ ├── Perfect_Number.js │ ├── README.md │ ├── bin_exp.js │ ├── catalan_number.js │ └── gcd_of_two_no.js ├── other │ ├── README.md │ ├── RemoveOuterParenthesis.js │ └── largeNumberFactorial.js ├── search │ ├── ExponentialSearch.js │ ├── FibonacciSearch.js │ ├── InterpolationSearch.js │ ├── JumpSearch.js │ ├── KMPalgorithm.js │ ├── ManacherAlgorithm.js │ ├── README.md │ ├── binary_search.js │ ├── linear_search.js │ └── ternary_search.js └── sort │ ├── BrickSort.js │ ├── BubbleSort.js │ ├── BucketSort.js │ ├── CombSort.js │ ├── GnomeSort.js │ ├── MergeSort.js │ ├── PancakeSort.js │ ├── README.md │ ├── ShakerSort.js │ ├── StoogeSort.js │ ├── TimSort.js │ ├── WaveFormSort.js │ ├── cycleSort.js │ ├── insertion_sort.js │ ├── quicksort.js │ ├── selectionSort.js │ └── sleepSort.js ├── Julia ├── Bit--Manipulation │ ├── count_num_of_set_bits.jl │ ├── left_rotate_bits.jl │ ├── minimum_xor_value.jl │ ├── no_of_bits_to_be_flipped_to_inter_convert_two_numbers.jl │ ├── power_of_2.jl │ ├── reverse_bits.jl │ ├── right_rotate_bits.jl │ └── toggle_kth_bit.jl ├── README.md ├── cp │ ├── GCD.jl │ ├── Maximum_subarray_sum.jl │ ├── Prime_factorization.jl │ ├── RainwaterTrapping.jl │ ├── Sieve_of_Eratosthenes.jl │ ├── factorials.jl │ ├── isPowerOf2.jl │ ├── knapsack.jl │ ├── painting_fence.jl │ ├── subsequence.jl │ └── subsetsOfArray.jl ├── dp │ ├── count_derangements.jl │ ├── cutting_a_rod.jl │ ├── fibonacci.jl │ ├── golomb_sequence.jl │ ├── length_longest_common_subsequence.jl │ ├── length_longest_common_substring.jl │ ├── length_longest_decreasing_subsequence.jl │ ├── length_longest_increasing_subsequence.jl │ ├── maximum_sum_decreasing_subsequence.jl │ ├── maximum_sum_increasing_subsequence.jl │ └── subset_sum.jl ├── math │ ├── armstrong_number.jl │ ├── automorphic_number.jl │ ├── catalan_number.jl │ ├── check_palindrome.jl │ ├── delannoy_number.jl │ ├── eulerian_number.jl │ ├── krishnamurthy_number.jl │ ├── lucas_number.jl │ ├── magic_number.jl │ ├── mystery_number.jl │ ├── neon_number.jl │ ├── noble_integer.jl │ ├── number_of_digits.jl │ ├── perfect_number.jl │ ├── pronic_number.jl │ ├── reverse_number.jl │ ├── sterns_diatomic_series.jl │ ├── strong_number.jl │ ├── sum_of_digits.jl │ ├── sum_of_divisors.jl │ ├── towerOfHanoi.jl │ └── tribonacci.jl ├── search │ ├── binary_search.jl │ ├── exponential_search.jl │ ├── fibonacci_search.jl │ ├── interpolation_search.jl │ ├── jump_search.jl │ ├── linear_search.jl │ ├── ternary_search.jl │ └── ternary_search_recursive.jl └── sort │ ├── bubble_sort.jl │ ├── circle_sort.jl │ ├── comb_sort.jl │ ├── insertion_sort.jl │ ├── merge_sort.jl │ ├── quick_sort.jl │ └── selection_sort.jl ├── Kotlin ├── BitManipulation │ ├── BasicBitOperations.kt │ ├── CountSetBits.kt │ ├── PowerOfTwo.kt │ ├── SingleNumber_I.kt │ └── XORFromOneToN.kt ├── Maths │ ├── Areas2D.kt │ ├── Areas3D.kt │ ├── Armstrong.kt │ ├── ArmstrongRecursive.kt │ ├── Factorial.kt │ ├── FibonacciNumber.kt │ ├── GraytoDecimalandDecimaltoGray.kt │ ├── HappyNumber.kt │ ├── PalindromeNumber.kt │ └── TowerofHanoi.kt ├── Readme.md ├── cp │ └── ReverseString.kt ├── search │ ├── BinarySearch.kt │ ├── ExponentialSearch.kt │ ├── LinearSearch.kt │ ├── StairCaseSearch.kt │ └── TernarySearch.kt └── sort │ ├── BubbleSort │ └── src │ │ └── BubbleSort.kt │ ├── InsertionSort │ └── src │ │ └── InsertionSort.kt │ ├── MergeSort │ └── src │ │ └── MergeSort.kt │ ├── QuickSort │ └── src │ │ └── QuickSort.kt │ ├── RadixSort │ └── src │ │ └── RadixSort.kt │ └── SelectionSort │ └── src │ └── SelectionSort.kt ├── LICENSE ├── LOGO ├── Logo1.png ├── Logo3.jpeg └── logo2.png ├── OPEN_SOURCE_EVENTS.md ├── PHP ├── readme.md └── sort │ ├── InsertionSort.php │ ├── SelectionSort.php │ ├── bubble_sort.php │ └── quick_sort.php ├── Python ├── Bit--Manipulation │ ├── check_collinearity_of_three_points.py │ ├── count_num_of_set_bits.py │ ├── left_rotate_bits.py │ ├── minimum_xor_value.py │ ├── no_of_bits_to_be_flipped_to_inter_convert_two_numbers.py │ ├── reverse_bits.py │ ├── right_rotate_bits.py │ └── toggle_kth_bit.py ├── Code_Template.md ├── Pathfinding │ ├── 2D_Astar.py │ ├── 2D_BFS.py │ ├── 2D_DFS_Iterative.py │ ├── 2D_DFS_Recursive.py │ ├── 2D_Dijkstra.py │ └── 2D_RRT.py ├── README.md ├── backtracking │ ├── Cryptarithmetic_Problem.py │ ├── Hamiltonian_Cycle.py │ ├── Knight's_Tour.py │ ├── M-coloring.py │ ├── Maze-Generation-Visualiser.py │ ├── N_Queens.py │ ├── RatInMaze.py │ ├── Subset_Sum.py │ ├── Tic_Tac_Toe.py │ ├── Tug_of_war.py │ ├── Water_Jug_Problem.py │ └── sudokuSolver.py ├── blockchain │ └── README.md ├── cp │ ├── Chololate_distribution.py │ ├── CountAnagrams.py │ ├── Cyclically_rotate.py │ ├── Find_First_and_Last_Position_of_Element_in_Sorted_Array.py │ ├── Generating_Power_Set.py │ ├── Hailstone_sequence.py │ ├── KMP_Algorithm.py │ ├── LetterCount.py │ ├── Maximum_Water_Container.py │ ├── Median_of_two_sorted_arrays.py │ ├── Minimize_Amplitude_After_K_Removals.py │ ├── Next_Permutation.py │ ├── Number_of_K-Length_Sublists_with_Average_at_Least _Target.py │ ├── Paint_Fence.py │ ├── Prime_factorisation_using_sieve.py │ ├── README.md │ ├── RabinKarp.py │ ├── Rabin_Karp.py │ ├── Run_Length_Encoding.py │ ├── SlidingWindowMaximum.py │ ├── Sort_An_Arrayof0s1sand2s.py │ ├── Target_Sum_Triplet.py │ ├── Trapping_rain_water.py │ ├── VowelsConsants.py │ ├── activity_selection.py │ ├── adjacent_elements_product.py │ ├── anagram_checker.py │ ├── anagram_problem.py │ ├── bulb_switcher.py │ ├── climbing-the-leaderboard.py │ ├── delete_node.py │ ├── find_Triplets_with_zero_sum.py │ ├── find_intersection_of_two_linked_lists.py │ ├── findingLeastPositiveNumber.py │ ├── house_robber.py │ ├── longest_Common_Prefix.py │ ├── max_sum.py │ ├── max_sum_k_consecutive_elements.py │ ├── maxsum_subarray_python.py │ ├── rainwater_harvesting.py │ ├── search_insert_position.py │ ├── smallest_sum_array.py │ ├── stable_marriage_problem.py │ ├── staircase_problem.py │ └── stock_span.py ├── cryptography │ ├── AES.py │ ├── AffineCipher.py │ ├── Burrows_Wheeler_transform.py │ ├── Caesar_Cipher.py │ ├── Columnar_Cipher.py │ ├── Diffie_Helman_Protocol.py │ ├── HillCipher.py │ ├── Keyword_Cipher.py │ ├── Playfair_Cipher.py │ ├── RSA_Algorithm.py │ ├── Rail_Fence_Cipher.py │ ├── Vernam_Cipher.py │ ├── XOR_cipher.py │ ├── monoalphabeticcipher.py │ └── vigenere_cipher.py ├── dp │ ├── Catalan_DP.py │ ├── CoinChange.py │ ├── Dice_Throw.py │ ├── EditDistance.py │ ├── House_Robber.py │ ├── Knapsack_01.py │ ├── Knapsack_Unbounded.py │ ├── Knapsack_fractional.py │ ├── Longest_Common_Subsequence.py │ ├── Longest_bitonic_subsequence.py │ ├── Longest_increasing_Subsequence.py │ ├── Matrix-Chain-Multiplication.py │ ├── Maximum_Profit.py │ ├── Partition_Problem.py │ ├── Ugly_Numbers.py │ ├── Unique_BST.py │ ├── binary_trees_with_n_nodes.py │ ├── coinTower.py │ ├── count_derangements.py │ ├── cutting_a_rod.py │ ├── golomb_sequence.py │ ├── length_common_decreasing_subsequence.py │ ├── length_longest_common_substring.py │ ├── maximum_sum_decreasing_subsequence.py │ ├── maximum_sum_increasing_subsequence.py │ ├── subset_sum.py │ └── tiling_problem_2xN.py ├── ds │ ├── AVL_Tree.py │ ├── BST_Level_Order_Traversal.py │ ├── Bestfit.py │ ├── Binary-Search-Tree-Validation.py │ ├── BinarySearchTree.py │ ├── Binary_tree_post_order.py │ ├── Circular_LinkedList.py │ ├── DiameterOfBinaryTree.py │ ├── Double_Ended_queue.py │ ├── Firstfit.py │ ├── Implementation_of_Stack_using_queues.py │ ├── Infix_To_Postfix_Conversion.py │ ├── Invert a Binary Tree.py │ ├── Leaf_nodes_BST.py │ ├── Linear_Probing_In_Hashing.py │ ├── MaxDistanceBetweenSameElements.py │ ├── Palindrome-doublylinkedlist.py │ ├── Prefix_to_postfix.py │ ├── Quadratic_Probing_in_hashing.py │ ├── Queue.py │ ├── Reverse_First_K_elements_of_Queue.py │ ├── Reverse_linked_list.py │ ├── Reverse_queue_using_stack.py │ ├── Right_view_of_binary_tree.py │ ├── SinglyLinkedList.py │ ├── Sparse_matrix_Operation.py │ ├── Stacks.py │ ├── Sum_of_Linked_list.py │ ├── SwapNodes-LinkedList.py │ ├── Tree_Iterative_InOrder_Traversal.py │ ├── Tree_Level_Order_Traversal.py │ ├── Tree_Traversals_In_Pre_Post_Order.py │ ├── Tree_preOrder_traversal.py │ ├── Trie.py │ ├── Worstfit.py │ ├── consecutive_sum_is_zero.py │ ├── dynamic_queue.py │ ├── dynamic_stack.py │ ├── identical_binary_tree.py │ ├── linkedListIntersection.py │ ├── loop_detection_in_LL.py │ ├── lowest_common_ancestor_bst.py │ ├── priority_queue.py │ ├── reverseWordsOfString.py │ ├── rotate_the_array_by_k_elements.py │ └── stack_using_list.py ├── graphs │ ├── Articulation_Point.py │ ├── Bellman_Ford.py │ ├── Bipartite_Graph.py │ ├── Bridge_Edge_in_Graph.py │ ├── Connected_Components.py │ ├── DFS.py │ ├── Depth_Of_Tree.py │ ├── Directed_Acyclic_Graph.py │ ├── Euler_circuit_and_Path.py │ ├── Floyd_Warshall_Algorithm.py │ ├── Hamiltonian_Path.py │ ├── Knight_Walk.py │ ├── Kruskal_Algorithm.py │ ├── Left_view_of_binary_tree.py │ ├── Negative_Cycle.py │ ├── Prim_Algorithm.py │ ├── Prims_Algo_dynamic.py │ ├── README.md │ ├── Rotten_Oranges.py │ ├── SCC_Kosaraju.py │ ├── SCC_Tarjan.py │ ├── Topological_Sort.py │ ├── Warshall.py │ ├── dijkstras_algorithm.py │ ├── height_of_given_tree.py │ └── top_view_binary_tree.py ├── math │ ├── Arctan.py │ ├── Area.py │ ├── Binary_Exponentiation.py │ ├── Catalan_Number.py │ ├── CheckArmstrongNumber.py │ ├── Chinese_Remainder_Theorem.py │ ├── Extended_Euclidean_Algorithm.py │ ├── Fibonacci.py │ ├── GCD_Euclidean_Algorithm.py │ ├── GCD_of_two_numbers.py │ ├── Hamming_distance.py │ ├── Happy_Number.py │ ├── HarshadNumber.py │ ├── K_largest.py │ ├── Large_number_factorial.py │ ├── Least_common_multiple.py │ ├── Lucas_Theorem.py │ ├── Lucky_Numbers.py │ ├── Magic_Number.py │ ├── Matrix_addition.py │ ├── Matrix_multiplication.py │ ├── Matrix_transpose.py │ ├── Natural_Logarithm_Algorithm.py │ ├── Neon_number.py │ ├── Next_Palindrome.py │ ├── Next_Prime_Number.py │ ├── Noble_Integer.py │ ├── Palindrome.py │ ├── Perfect_Number.py │ ├── Pronic_numbers.py │ ├── README.md │ ├── Sieve-of-eratosthenes.py │ ├── Sine_Function.py │ ├── Squares_in_2n_Chessboard.py │ ├── Strassen's_Matrix_Mul.py │ ├── Strong_Number.py │ ├── UglyNumber.py │ ├── ackermann_function.py │ ├── count_of_digits.py │ ├── count_of_divisors.py │ ├── delannoy_number.py │ ├── double_factorial.py │ ├── euler_totient_function.py │ ├── factorial.py │ ├── fibonacci_recursion.py │ ├── min_max_sum.py │ ├── perfect_square.py │ ├── positive_decimal_to_binary.py │ ├── prime_number.py │ ├── prime_number_using_sieve_of_Eratosthenes.py │ ├── reverse_a_number.py │ ├── roots_of_quadratic_equation.py │ ├── sterns_diatomic_series.py │ ├── sum_of_digits.py │ ├── sum_of_divisors.py │ └── tribonacci.py ├── ml │ ├── Amazon_Alexa_Reviews_Analysis.ipynb │ ├── Ames_House_Price_Prediction.ipynb │ ├── Bell_state_creation.ipynb │ ├── Churn_Risk_Score_Prediction.ipynb │ ├── DecisionTree_From_Scratch.ipynb │ ├── E-Mail_Classification.ipynb │ ├── Flight_Delay_Predictions.ipynb │ ├── Ice_Cream_Revenue_Prediction.ipynb │ ├── Income_Classification.ipynb │ ├── Iris_Classifier_using_Keras.ipynb │ ├── K_nearest_neighbors.ipynb │ ├── Laptop_Price_Prediction.ipynb │ ├── Linear_Regression.ipynb │ ├── Linear_Regression_using_PyTorch.ipynb │ ├── Loan_Eligibility_Prediction.ipynb │ ├── Logically_weighted_regression.py │ ├── Logistic_Regression.ipynb │ ├── Mobile_Price_Range_Classification.ipynb │ ├── NASA_Asteroids_Classification.ipynb │ ├── Naive_Bayes_Classifier.ipynb │ ├── Naive_Bayes_from_Scratch.py │ ├── Numerical_outlier_method.ipynb │ ├── Questions_to_Subject_Classification.ipynb │ ├── Solar_Radiation_Prediction.ipynb │ ├── Startup_Profit_Prediction.ipynb │ ├── Support_Vector_Machine.ipynb │ ├── White_Wine_Quality_Prediction.ipynb │ └── principal_component_analysis.ipynb ├── other │ ├── Arrange_The_String.py │ ├── Check_Inversion.py │ ├── CountTriplets.py │ ├── Count_Articles.py │ ├── Count_Inversion.py │ ├── Distinct_elements_count.py │ ├── HappyNumber.py │ ├── Kadanes_Algorithm.py │ ├── KeypadSequence.py │ ├── Longest_Consecutive_Subsequence.py │ ├── Maximum_Product_Subarray.py │ ├── Maximum_Square_Matrix.py │ ├── Minimum_Sum_Partition.py │ ├── Moore_Algorithm.py │ ├── Next_premutation.py │ ├── Plot_Graph.py │ ├── Possible_code_recursion.py │ ├── Program_to_rotation_array.py │ ├── Rearrange_the_neagtive_positive_element.py │ ├── Reverse_string_using_stack.py │ ├── Russian_Peasant_Algorithm.py │ ├── Satellite Image Analysis using numpy.ipynb │ ├── Segment_Tree.py │ ├── SortColors-DutchNationalFlag.py │ ├── Subarray_with_sum0.py │ ├── Subsequence_check.py │ ├── Subsequence_recursion.py │ ├── Swap_two_nibbles.py │ ├── Tower_of_Hanoi.py │ ├── TripletSumValue.py │ ├── Union_of_two_arrays.py │ ├── Unique_number_III.py │ ├── Wave_Array.py │ ├── best_time_buy_And_sell_stock.py │ ├── check_valid_parenthesis_string.py │ ├── common_elements.py │ ├── count_pair_with_given_sum.py │ ├── equilibrium_point_in_array.py │ ├── find_freq_using_bs.py │ ├── find_the_numbers.py │ ├── left_nonRepeating_char.py │ ├── longest_Substring.py │ ├── merge_interval.py │ ├── merge_sorted_arrays.py │ ├── minimize_the_jump.py │ ├── painter_partition.py │ ├── remove_outermost_parenthesis.py │ ├── stringkth.py │ └── sudoku_backtracking.py ├── search │ ├── 8_Puzzle_Problem_using_A_star_Algorithm.py │ ├── 8_Puzzle_Problem_using_BFS.py │ ├── Interpolation_Search.py │ ├── Linear_Search.py │ ├── Z_Algorithm.py │ ├── bfs.py │ ├── bilinear.py │ ├── binarysearch.py │ ├── binarysearch_iterative.py │ ├── dfs.py │ ├── exponential_search.py │ ├── fibonacci_search.py │ ├── jump_search.py │ ├── random_search_las_vegas.py │ ├── random_select.py │ ├── three_sum_problem.py │ └── unbounded_binary_search.py ├── sort │ ├── Bead_Sort.py │ ├── Bogo_sort.py │ ├── Bubble_Sort.py │ ├── Bucket_sort.py │ ├── Counting_Sort.py │ ├── Heap_sort.py │ ├── IntroSort.py │ ├── ListTuplesort.py │ ├── Matrix_Sort.py │ ├── Optimized_Bubble_Sort.py │ ├── Parallel_MergeSort.py │ ├── QuickSort.py │ ├── README.md │ ├── Radix_Sort.py │ ├── Selection_Sort.py │ ├── Sequential_MergeSort.py │ ├── Shell_Sort.py │ ├── Sleep_sort.py │ ├── TimSort.py │ ├── Tree_Sort.py │ ├── cocktail_sort.py │ ├── comb_sort.py │ ├── gnome_sort.py │ ├── insertion.py │ ├── pancakesorting.py │ └── topological_sort.py └── string │ └── KMP.py ├── Q-Sharp ├── README.md ├── blockchain │ └── README.md ├── cp │ └── README.md ├── cryptography │ └── README.md ├── dp │ └── README.md ├── ds │ └── README.md ├── graphs │ └── README.md ├── math │ └── README.md ├── other │ └── README.md ├── search │ └── README.md └── sort │ └── README.md ├── README.md ├── Resources ├── Bubble_Sort.md ├── Counting_Sort.md ├── Heap_Sort.md ├── Linear_Search.md ├── Pancake_sort.md ├── README.md ├── Radix_Sort.md ├── Selection_Sort.md ├── Shell_sort.md └── Sleep_sort.md ├── SECURITY.md ├── _config.yml ├── go.mod └── img ├── fork.png ├── git add.png ├── git branch.png ├── git checkout.png ├── git clone.png ├── git commit.png ├── git push.png ├── grover.png ├── issue.png ├── issue_template_get_started_button.png ├── neo_algo.png ├── new_issue.png ├── pull_2.png └── pull_request.png /.deepsource.toml: -------------------------------------------------------------------------------- 1 | version = 1 2 | 3 | [[analyzers]] 4 | name = "python" 5 | enabled = true 6 | 7 | [analyzers.meta] 8 | runtime_version = "3.x.x" 9 | type_checker = "mypy" 10 | 11 | [[analyzers]] 12 | name = "go" 13 | enabled = true 14 | 15 | [analyzers.meta] 16 | import_paths = ["github.com/TesseractCoding/NeoAlgo"] 17 | 18 | [[analyzers]] 19 | name = "javascript" 20 | enabled = true 21 | 22 | [analyzers.meta] 23 | environment = ["nodejs"] 24 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.ipynb linguist-vendored 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🐛 Bug Report 3 | about: Submit a bug report to help us improve 4 | labels: "bug" 5 | --- 6 | 7 | ## 🐛 Bug Report 8 | 9 | (A clear and concise description of what the bug is.) 10 | 11 | ### Have you read the [Contributing Guidelines on Pull Requests](https://github.com/TesseractCoding/NeoAlgo/blob/master/CONTRIBUTING.md#reporting-new-issues)? 12 | 13 | (Write your answer here.) 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/documentation.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 📚 Documentation 3 | about: Report an issue related to documentation 4 | labels: "documentation" 5 | --- 6 | 7 | ## 📚 Documentation 8 | 9 | (A clear and concise description of what the issue is.) 10 | 11 | ### Have you read the [Contributing Guidelines on Pull Requests](https://github.com/TesseractCoding/NeoAlgo/blob/master/CONTRIBUTING.md#reporting-new-issues)? 12 | 13 | (Write your answer here.) 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 🚀 Feature 3 | about: Submit a proposal for a new feature 4 | labels: "feature" 5 | --- 6 | 7 | ## 🚀 Feature 8 | 9 | (A clear and concise description of what the feature is.) 10 | 11 | ### Have you read the [Contributing Guidelines on Pull Requests](https://github.com/TesseractCoding/NeoAlgo/blob/master/CONTRIBUTING.md#reporting-new-issues)? 12 | 13 | (Write your answer here.) 14 | 15 | ## Motivation 16 | 17 | (Please outline the motivation for the proposal.) 18 | 19 | ## Pitch 20 | 21 | (Please explain why this feature should be implemented and how it would be used.) 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/proposal.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: 💥 Proposal 3 | about: Propose a non-trivial change to NeoAlgo 4 | labels: "proposal" 5 | --- 6 | 7 | ## 💥 Proposal 8 | 9 | (A clear and concise description of what the proposal is.) 10 | 11 | ### Have you read the [Contributing Guidelines on Pull Requests](https://github.com/TesseractCoding/NeoAlgo/blob/master/CONTRIBUTING.md#reporting-new-issues)? 12 | 13 | (Write your answer here.) 14 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: ❓ Questions and Help 3 | about: If you have questions, please check the below links 4 | labels: "question" 5 | --- 6 | 7 | ## ❓ Questions and Help 8 | 9 | ### Please note that this issue tracker is not a help form and this issue will be closed. 10 | 11 | Please contact us instead. 12 | 13 | - [Website](https://www.tesseractcoding.tech/) 14 | - [Email](team@tesseractcoding.tech) 15 | - [GitHub](https://github.com/TesseractCoding) 16 | - [Instagram](https://www.instagram.com/tesseractcoding/) 17 | - [LinkedIn](https://www.linkedin.com/company/tesseract-coding/) 18 | - [Medium](https://medium.com/tesseract-coding) 19 | - [Telegram](https://t.me/tesseractcoding) 20 | - [YouTube](https://www.youtube.com/c/TesseractCoding/) 21 | -------------------------------------------------------------------------------- /.github/auto_assigner_config.yml: -------------------------------------------------------------------------------- 1 | # Set to true to add reviewers to pull requests 2 | addReviewers: true 3 | 4 | # Set to true to add assignees to pull requests 5 | addAssignees: false 6 | 7 | # A list of reviewers to be added to pull requests (GitHub user name) 8 | reviewers: 9 | - HarshCasper 10 | - iamrajiv 11 | - atarax665 12 | -------------------------------------------------------------------------------- /.github/issues_labeler.yml: -------------------------------------------------------------------------------- 1 | C: 2 | - "( C )" 3 | C-Plus-Plus: 4 | - "(C-Plus-Plus|CPP|cpp)" 5 | C-Sharp: 6 | - "(C-Sharp|csharp|C#)" 7 | Go: 8 | - "(Go|GO|Golang)" 9 | Java: 10 | - "(Java|java)" 11 | JavaScript: 12 | - "(JavaScript|JAVASCRIPT|Javascript|javascript|JS|js)" 13 | Python: 14 | - "(Python|PYTHON|python)" 15 | Q-Sharp: 16 | - "(Q-Sharp|qsharp|Q#)" 17 | enhancement: 18 | - "(enhancement)" 19 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | C: 2 | - "( C )" 3 | C-Plus-Plus: 4 | - "(C-Plus-Plus|CPP|cpp|Cpp)" 5 | C-Sharp: 6 | - "(C-Sharp|csharp|C#|C-SHARP|C-sharp|c-sharp|CSHARP)" 7 | Go: 8 | - "(Go|GO|Golang|golang|GOLANG)" 9 | Java: 10 | - "(Java|java|JAVA)" 11 | JavaScript: 12 | - "(JavaScript|JAVASCRIPT|Javascript|javascript|JS|js|javaScript)" 13 | Python: 14 | - "(Python|PYTHON|python)" 15 | Q-Sharp: 16 | - "(Q-Sharp|qsharp|Q#|Q-SHARP|Q-sharp|q-sharp|QSHARP)" 17 | enhancement: 18 | - "(enhancement)" 19 | Dart: 20 | - "(Dart|dart|DART)" 21 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ### Have you read the [Contributing Guidelines on Pull Requests](https://github.com/TesseractCoding/NeoAlgo/blob/master/CONTRIBUTING.md#pull-requests)? 12 | 13 | (Write your answer here.) 14 | 15 | ### Description 16 | 17 | (Write your answer here.) 18 | 19 | ### Checklist 20 | 21 | - [ ] I've read the contribution guidelines. 22 | - [ ] I've checked the issue list before deciding what to submit. 23 | - [ ] I've edited the `README.md` and link to my code. 24 | 25 | ## Related Issues or Pull Requests 26 | 27 | (Write your answer here.) 28 | -------------------------------------------------------------------------------- /.github/stale.yml: -------------------------------------------------------------------------------- 1 | # Number of days of inactivity before an issue becomes stale 2 | daysUntilStale: 7 3 | # Number of days of inactivity before a stale issue is closed 4 | daysUntilClose: 8 5 | # Issues with these labels will never be considered stale 6 | exemptLabels: 7 | - bug 8 | - do not merge yet 9 | - help wanted 10 | - high priority 11 | - pinned 12 | # Label to use when marking an issue as stale 13 | staleLabel: stale 14 | # Comment to post when marking an issue as stale. Set to `false` to disable 15 | markComment: > 16 | This issue has been automatically marked as stale because it has not had 17 | recent activity. It will be closed if no further activity occurs. Thank you 18 | for your contributions. 19 | # Comment to post when closing a stale issue. Set to `false` to disable 20 | closeComment: > 21 | Please reopen this issue once you commit the changes requested or 22 | make improvements on the code. Thank you for your contributions. 23 | -------------------------------------------------------------------------------- /.github/workflows/Auto_Issue_Closer.yml: -------------------------------------------------------------------------------- 1 | # Written By XZANATOL 2 | name: Auto Issue Closer on Merge 3 | 4 | on: 5 | pull_request: 6 | # Will trigger on closed PRs 7 | types: [closed] 8 | 9 | jobs: 10 | Close_Issue: 11 | 12 | runs-on: ubuntu-latest 13 | # Checks if PR is merged (subflag) 14 | if: ${{ github.event.pull_request.merged == true }} 15 | 16 | steps: 17 | - name: Closes issues related to a merged pull request. 18 | uses: ldez/gha-mjolnir@v1.0.3 19 | env: 20 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/Issue-assign.yml: -------------------------------------------------------------------------------- 1 | # name: Assign 2 | 3 | # on: 4 | # schedule: 5 | # - cron: '*/2 * * * *' 6 | # issue_comment: 7 | # types: [created] 8 | 9 | # jobs: 10 | # slash_assign: 11 | # # If the acton was triggered by a new comment that starts with `/assign` 12 | # # or a on a schedule 13 | # if: > 14 | # (github.event_name == 'issue_comment' && startsWith(github.event.comment.body, '/assign')) || 15 | # github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' 16 | # runs-on: ubuntu-latest 17 | # steps: 18 | # - name: Assign the user or unassign stale assignments 19 | # uses: JasonEtco/slash-assign-action@v0.0.3 20 | # with: 21 | # assigned_label: Assigned 22 | # days_until_warning: 5 23 | # days_until_unassign: 7 24 | # stale_assignment_label: Open 25 | -------------------------------------------------------------------------------- /.github/workflows/Issue_watcher.yml: -------------------------------------------------------------------------------- 1 | name: Issue_watcher 2 | 3 | on: 4 | issues: 5 | types: [opened] 6 | 7 | jobs: 8 | first-job: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout code 12 | uses: actions/checkout@main 13 | - name: Run Action 14 | uses: TesseractCoding/Issue_Watcher@main 15 | with: 16 | token: '${{ secrets.GITHUB_TOKEN }}' 17 | author: '${{github.actor}}' 18 | repo: TesseractCoding/NeoAlgo 19 | maxIssue: 2 20 | -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: 4 | issues: 5 | types: [opened] 6 | pull_request: 7 | types: [opened] 8 | 9 | jobs: 10 | greeting: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: Karthik-Nayak98/Greeting-action@main 14 | with: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | issue_message: 'Hello @${{github.actor}},
17 | Thank you for opening an issue. :partying_face:
18 | To get assigned to this particular issue please use /assign
19 | Check this guide before contributing.' 20 | PR_message: 21 | '

:partying_face: Congratulations :tada:

:pray: 22 | Thank you @${{github.actor}} for taking out your time and contributing to our project. Our team will now review this and if everything looks good it will be merged.' -------------------------------------------------------------------------------- /.github/workflows/issues_labeler.yml: -------------------------------------------------------------------------------- 1 | name: Issues Labeler 2 | on: 3 | issues: 4 | types: [opened, edited] 5 | pull_request_target: 6 | types: [opened, reopened, edited, closed, synchronize] 7 | jobs: 8 | labeler: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: github/issue-labeler@v2.0 12 | with: 13 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 14 | configuration-path: .github/issues_labeler.yml 15 | enable-versioned-regex: 0 16 | -------------------------------------------------------------------------------- /.github/workflows/java-format.yml: -------------------------------------------------------------------------------- 1 | name: Google java formatter 2 | 3 | on: 4 | push: 5 | paths: 6 | - "Java/**" 7 | pull_request: 8 | paths: 9 | - "Java/**" 10 | 11 | jobs: 12 | format: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout codebase 17 | uses: actions/checkout@v2 18 | 19 | - name: Setup java environment 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: "11" 23 | 24 | - name: Setup code formatter 25 | uses: axel-op/googlejavaformat-action@v3 26 | with: 27 | args: "--skip-javadoc-formatting --replace" 28 | commitMessage: "FORMAT: Google java formatter" 29 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | name: "PR_labeler" 2 | on: 3 | pull_request_target: 4 | types: [opened, reopened, edited, closed, synchronize] 5 | 6 | 7 | jobs: 8 | triage: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/labeler@main 12 | with: 13 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 14 | configuration-path: .github/labeler.yml 15 | -------------------------------------------------------------------------------- /.github/workflows/reviewer_auto_assigner.yml: -------------------------------------------------------------------------------- 1 | name: 'Auto Assign Reviewers to Pull Requests' 2 | on: 3 | pull_request: 4 | types: [opened, reopened] 5 | jobs: 6 | add-reviews: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: kentaro-m/auto-assign-action@v1.1.2 10 | with: 11 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 12 | configuration-path: .github/auto_assigner_config.yml 13 | -------------------------------------------------------------------------------- /C-Plus-Plus/Bit--Manipulation/Brian_Kernighan's_Algorithm.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Brian Kernighan’s Algorithm: To get the number of set bits 3 | For eg :- 5 can be represented as 101 number of set bits are 2 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | int main() 9 | { 10 | int n; 11 | cout<<"Enter number \n"; 12 | cin>>n; 13 | int c=0; 14 | while (n) { 15 | n &= (n - 1); 16 | c++; 17 | } 18 | cout<< c; 19 | } 20 | 21 | /* 22 | Time Complexity: O(logn) 23 | Space Complexity: O(1) 24 | */ 25 | 26 | /*Sample Input: 27 | Example 1:- 28 | Enter number 29 | 5 30 | Example 2:- 31 | Enter number 32 | 987 33 | 34 | Sample Output: 35 | Example 1:- 2 36 | Example 2:- 8 37 | */ 38 | 39 | -------------------------------------------------------------------------------- /C-Plus-Plus/Bit--Manipulation/Count_no_of_set_bits.cpp: -------------------------------------------------------------------------------- 1 | //Count No of Set Bits 2 | 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int n,k; 8 | cout<<"Enter number \n"; 9 | cin>>n; 10 | int res=0; 11 | while(n>0) 12 | { 13 | res = res + (n & 1); 14 | n=n>>1; 15 | } 16 | cout< 7 | using namespace std; 8 | //to find missing number xor the array elements 9 | // xor all elements from 1 to N 10 | // Xor both the above two steps 11 | int main() 12 | { 13 | int n; 14 | cout<<"Enter number of elements \n"; 15 | cin>>n; 16 | vectorarr; 17 | int a; 18 | for(int i=0;i>a; 21 | arr.push_back(a); 22 | } 23 | int res=0; 24 | for(int i=0;i 7 | using namespace std; 8 | 9 | bool power_of_2(int n) 10 | { 11 | // if zero then it will return true 12 | return (n&& !(n&n-1)); 13 | } 14 | int main() 15 | { 16 | int num; 17 | cout<<"Enter the number : "<>num; 19 | power_of_2(num)? cout<<"Yes\n": cout<<"No\n"; 20 | } 21 | 22 | /* 23 | Time complexity : O(1) 24 | Space complexity : O(1) 25 | */ 26 | 27 | /* 28 | Input : 29 | Enter the number : 30 | 64 31 | 32 | Output : 33 | Yes 34 | 35 | */ 36 | 37 | -------------------------------------------------------------------------------- /C-Plus-Plus/Bit--Manipulation/Swap_even_and_odd_bits.cpp: -------------------------------------------------------------------------------- 1 | //Swap Even and Odd Bits 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | unsigned int x; 9 | cout << "Enter number \n"; 10 | cin >> x; 11 | 12 | // Get all even bits of x 13 | unsigned int even_bits = x & 0xAAAAAAAA; 14 | 15 | // Get all odd bits of x 16 | unsigned int odd_bits = x & 0x55555555; 17 | // Right shift even bits 18 | even_bits >>= 1; 19 | // Left shift odd bits 20 | odd_bits <<= 1; 21 | // Combine even and odd bits 22 | cout << (even_bits | odd_bits); 23 | } 24 | 25 | /* 26 | Time Complexity: O(1) 27 | Space Complexity: O(1) 28 | */ 29 | 30 | /*Sample Input: 31 | Example 1:- 32 | Enter number 33 | 50 34 | Example 2:- 35 | Enter number 36 | 994 37 | 38 | Sample Output: 39 | Example 1:- 40 | 49 41 | Example 2:- 42 | 997 43 | */ 44 | 45 | -------------------------------------------------------------------------------- /C-Plus-Plus/blockchain/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/Build_wall.cpp: -------------------------------------------------------------------------------- 1 | /*Problem Statement: 2 | Given a wall of size 4XN, and tiles of sizes(1,4) and (4,1). 3 | In how many ways can you build a wall */ 4 | 5 | #include 6 | using namespace std; 7 | 8 | int buildWall(int n) 9 | { 10 | if(n<=3) 11 | { 12 | return 1; 13 | } 14 | int ans1=buildWall(n-1); 15 | int ans2=buildWall(n-4); 16 | 17 | return ans1+ans2; 18 | } 19 | 20 | int main() 21 | { 22 | int n; 23 | cout<<"Enter the size of the wall: "<>n; 25 | cout<<"The number of ways are: "< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin >> t; 7 | while (t--) { 8 | int i = 0, j = 0; //i will point str1 and j will point str2 9 | string str1, str2; //str1 is substring 10 | cin >> str1 >> str2; //str2 is full string 11 | while (i < str1.length() && j < str2.length()) { 12 | if (str1[i] == str2[j]) { 13 | i++; 14 | } 15 | j++; 16 | } 17 | if (i == str1.length()) { 18 | cout << "Yes, str1 is substring of str2"; 19 | } 20 | else { 21 | cout << "No, str1 is not substring of str2"; 22 | } 23 | cout << endl; 24 | } 25 | return 0; 26 | } 27 | 28 | /*Time Complexity: O(n) 29 | Input: 30 | 2 31 | WGA AWRGNA 32 | QBR EQVBA 33 | Output: 34 | Yes, str1 is substring of str2 35 | No, str1 is not substring of str2 36 | */ 37 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/Container_with_most_water.cpp: -------------------------------------------------------------------------------- 1 | class Container_with_most_Water { 2 | public: 3 | int calculate(int i, int j, int x1, int x2){ 4 | int part1 = min(x1,x2); 5 | return part1 * abs(j - i); 6 | } 7 | 8 | int maxArea(vector& height) { 9 | int max = 0; 10 | int i = 0; // left pointer 11 | int j = height.size() - 1; // right pointer 12 | 13 | while (i < j){ 14 | int curr = calculate(i,j, height[i], height[j]); 15 | if (curr > max) max = curr; 16 | if (height[i] < height[j]) i++; 17 | else j--; 18 | } 19 | return max; // Returning maxarea 20 | } 21 | }; 22 | 23 | /* 24 | TIME COMPLEXITY 25 | 2 POINTER APPROACH USED 26 | O(N) where n is the size of the array 27 | 28 | TEST CASE 29 | 30 | INPUT 31 | [1,8,6,2,5,4,8,3,7] 32 | OUTPUT 33 | 49 34 | */ 35 | 36 | 37 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/Generic_Swaps.cpp: -------------------------------------------------------------------------------- 1 | /* This programm is used to swap any data type 2 | that is a number or a character and etc. 3 | It is make our code efficient and workful. */ 4 | 5 | #include 6 | using namespace std; 7 | 8 | // This is a function template 9 | // Calling the function by reference 10 | template void swap(X *a,X *b) 11 | { 12 | X temp; 13 | temp = *a; 14 | *a = *b; 15 | *b = temp; 16 | } 17 | 18 | int main(){ 19 | 20 | int n,m; 21 | cout<<"\n Enter two Integer :"; 22 | cin >> n >> m; 23 | 24 | char a,b; 25 | cout<<"\n Enter two Charcter :"; 26 | cin >> a >> b; 27 | 28 | swap(&n,&m); //calling function to swap integer 29 | swap(&a,&b); // calling function to swap char 30 | 31 | cout<<"\n Swapped n,m :"<< n <<" "<< m << endl; 32 | cout<<"\n Swapped a,b :"<< a <<" "<< b << endl; 33 | 34 | return 0; 35 | } 36 | /* 37 | Time-Complexity = O(N) 38 | Space-Complexity = O(N) 39 | */ 40 | 41 | /* 42 | Input: 43 | 1 2 or a b 44 | Output: 45 | 2 1 or b a 46 | */ 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/Josephus.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Josephus problem is a famous problem. 3 | In each iteration we kill the every kth 4 | person in a circular arrangement of n persons. 5 | Find the person who is alive at the end. 6 | 0-based indexing 7 | link to the problem : https://en.wikipedia.org/wiki/Josephus_problem 8 | **/ 9 | 10 | #include 11 | using namespace std; 12 | 13 | int solution(int n, int k) { 14 | if (n == 1) 15 | return 0; 16 | return (k + solution(n - 1, k)) % n; 17 | } 18 | 19 | int main() { 20 | int people, gap; 21 | cin >> people >> gap; 22 | cout << solution(people, gap) << '\n'; 23 | return 0; 24 | } 25 | 26 | /** 27 | Input : 28 | 4 2 29 | Output : 30 | 0 31 | 32 | Time Complexity : O(n) 33 | Space Complexity : O(1) 34 | **/ 35 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/Kadane_Algorithm.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int max_sum_subarray(int a[], int n){ 5 | 6 | int max_ending=a[0]; 7 | 8 | int ans=a[0]; 9 | 10 | for(int i=1;i>n; 23 | 24 | int a[n]; 25 | for(int i=0;i>a[i]; 27 | 28 | cout< 8 | using namespace std; 9 | 10 | int min_swap_needed(int a[],int n) 11 | { 12 | int swap=0; 13 | for(int i=0;i>n; 31 | int a[n]; 32 | for(int i=0;i>a[i]; 33 | int swap; 34 | swap=min_swap_needed(a,n); 35 | cout< 3 | using namespace std; 4 | 5 | void printSubsequences(string str, string curr="", int idx = 0){ 6 | //Base case 7 | if(idx == str.size()){ 8 | cout << curr << endl; 9 | return; 10 | } 11 | //Recursive call when character does not get added to curr 12 | printSubsequences(str, curr, idx + 1); 13 | //Recursive call when character gets added to curr 14 | printSubsequences(str, curr + str[idx], idx + 1); 15 | } 16 | 17 | int main() { 18 | string s; 19 | cout << "Enter the string"; 20 | cin >> s; 21 | printSubsequences(s, "", 0); 22 | return 0; 23 | } 24 | 25 | /* 26 | Time complexity : O(n) 27 | Space complexity : O(1) 28 | */ 29 | 30 | /*Example: 31 | Input : s = "abcd" 32 | Output : 33 | 34 | d 35 | c 36 | cd 37 | b 38 | bd 39 | bc 40 | bcd 41 | a 42 | ad 43 | ac 44 | acd 45 | ab 46 | abd 47 | abc 48 | abcd */ 49 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/String_to_int.cpp: -------------------------------------------------------------------------------- 1 | class String_to_int { 2 | public: 3 | int myAtoi(string str) { 4 | if (str.empty()) return 0; 5 | int i = 0, sign = 1; 6 | while (i + 1 < str.size() && isspace(str[i])) ++i; 7 | 8 | long res = 0; 9 | if (str[i] == '-' || str[i] == '+') sign = 44 - str[i++]; 10 | 11 | while (i < str.size()) { 12 | if (isdigit(str[i])) res = 10 * res + str[i++] - '0'; 13 | else return res * sign; 14 | if (res > INT_MAX) return sign == -1 ? INT_MIN : INT_MAX; 15 | } 16 | return res * sign; 17 | } 18 | }; 19 | 20 | /* 21 | 22 | TIME COMPLEXITY: 0(N) where N is length of string 23 | SPACE COMPLEXITY: o(1) 24 | TEST CASE 25 | 26 | Input: "42" 27 | Output: 42 28 | 29 | Input: "4193 with words" 30 | Output: 4193 31 | 32 | */ 33 | 34 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/ToggleKthBitFromRight.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Toggle kth bit from the right. 3 | i.e. For a given number n, if k-th bit from right is 0, then toggle it to 1 4 | and if it is 1 then, toggle it to 0. 5 | */ 6 | 7 | #include 8 | using namespace std; 9 | 10 | int main() { 11 | int n, k; 12 | //n=integer 13 | cin >> n >> k; 14 | int ans = (n ^ (1 << (k - 1))); 15 | cout << ans; 16 | return 0; 17 | } 18 | 19 | 20 | /* 21 | input: 22 | 6 2 23 | ouput: 24 | 4 25 | constraint: 26 | n is positive 27 | */ 28 | 29 | /* 30 | time-complexity: O(1) 31 | */ 32 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/first1_binsearch.cpp: -------------------------------------------------------------------------------- 1 | /*Code to find the first index in which 1 appears in an array of 0 and 1 2 | APPROACH USED -Binary Search 3 | */ 4 | #include 5 | using namespace std; 6 | int binSearch(int a[],int n) 7 | { 8 | int l=0,r=n-1,mid=0; 9 | while(l<=r) 10 | { 11 | mid=(l+r)/2; 12 | if(a[mid]==1 && (mid==0 || a[mid-1]==0)) 13 | return mid+1; 14 | else if(a[mid]==1) 15 | r=mid-1; 16 | else l=mid+1; 17 | } 18 | return -1; 19 | } 20 | int main() 21 | { 22 | int n; 23 | cin>>n; 24 | int a[n]; 25 | cout<<"Enter only 1 and 0 in sorted order\n"; 26 | for(int i=0;i>a[i]; 28 | sort(a,a+n); 29 | cout< 7 | using namespace std; 8 | 9 | int friendsPairing(int n) 10 | { 11 | if(n==0 or n==1) 12 | { 13 | return 1; 14 | } 15 | if(n==2) 16 | { 17 | return 2; 18 | } 19 | int ans1=friendsPairing(1)*friendsPairing(n-1); 20 | int ans2=friendsPairing(2)*friendsPairing(n-2); 21 | 22 | return ans1+ans2; 23 | } 24 | int main() 25 | { 26 | int n; 27 | cout<<"Enter total number of friends: "<>n; 29 | cout<<"Total ways: "< 2 | 3 | using namespace std; 4 | 5 | typedef long long int ll; 6 | 7 | string decimalToBinary(ll n) 8 | { 9 | string s = bitset<64> (n).to_string(); // stl to convert integer tobinary and convert into string 10 | 11 | //Finding the first occurance of "1" 12 | //to strip off the leading zeroes. 13 | const auto loc1 = s.find('1'); 14 | 15 | if(loc1 != string::npos) 16 | return s.substr(loc1); 17 | 18 | return "0"; 19 | } 20 | 21 | 22 | int main() { 23 | 24 | int n; 25 | cout<<"Enter a number: "; 26 | cin>>n; 27 | cout<<"binary string of given number is :"<< decimalToBinary(n); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/maxNumber.cpp: -------------------------------------------------------------------------------- 1 | /*Code for maximum number formed from the given array of two digit numbers 2 | Given: An array of two digit numbers 3 | Objective: Form the maximum number 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | int myCompare(string X, string Y) 9 | { 10 | string XY = X.append(Y); 11 | string YX = Y.append(X); 12 | return XY.compare(YX) > 0 ? 1 : 0; 13 | } 14 | int printLargest(vector str) 15 | { 16 | sort(str.begin(), str.end(), myCompare); 17 | for (int i = 0; i < str.size(); i++) 18 | cout << str[i]; 19 | } 20 | int main() 21 | { 22 | vector str; 23 | long long int n; 24 | cin >> n; 25 | string s; 26 | for (int i = 0; i < n; i++) 27 | { 28 | cin >> s; 29 | str.push_back(s); 30 | } 31 | printLargest(str); 32 | } 33 | /* 34 | Time Complexity:O(n) 35 | Example: 36 | Input: 37 | 5 38 | 12 34 22 45 20 39 | Output: 40 | 4534222012 41 | */ 42 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/power.cpp: -------------------------------------------------------------------------------- 1 | /* Program to calculate b^n%m . This program also known as 2 | Recursive Modular Exponentiation */ 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | int power(int b,int n,int m) 9 | { 10 | if(n==0) 11 | return 1; 12 | else if(n%2==0) 13 | return power(b,n/2,m)*power(b,n/2,m)%m; 14 | else 15 | return power(b,n/2,m)*power(b,n/2,m)%m*b%m; 16 | } 17 | int main() 18 | { 19 | int b,n,m; 20 | cout<<"Enter base \n"; 21 | cin>>b; 22 | cout<<"Enter Exponent \n"; 23 | cin>>n; 24 | cout<<"Enter Value to take modulus\n"; 25 | cin>>m; 26 | cout<<"\nAnswer of b ^ n % m : "< 4 | using namespace std; 5 | 6 | void printallcodes(string number, string ans) { 7 | if (number.size() == 0) { //Base case 8 | cout << ans << endl; 9 | return; 10 | } 11 | 12 | int ch = number[0] - '0'; 13 | 14 | if (ch != 0) { 15 | char code = char(ch - 1 + 'a'); //Extracting alphabet from its value 16 | string rstr = number.substr(1); 17 | printallcodes(rstr, ans + code); 18 | } 19 | 20 | if (number.size() >= 2) { 21 | int num = stoi(number.substr(0, 2)); 22 | 23 | if (num >= 1 && num <= 26) { 24 | char code = char(num - 1 + 'a'); 25 | string rstr = number.substr(2); 26 | printallcodes(rstr, ans + code); 27 | } 28 | } 29 | } 30 | 31 | int main() { 32 | string number; 33 | cout << "Enter the number"; 34 | cin >> number; 35 | printallcodes(number, ""); 36 | return 0; 37 | } 38 | 39 | /* 40 | Example: 41 | Input: s = "1123" 42 | Output: 43 | aabc 44 | aaw 45 | alc 46 | kbc 47 | kw 48 | */ 49 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/reverseWords.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Code to reverse individual words in a sentence without using stacks 3 | */ 4 | 5 | #include 6 | using namespace std; 7 | 8 | void reverseWord(string s[],int n) 9 | { 10 | for(int i=0;i>n; 23 | cout<<"Enter the sentence: "; 24 | string st[n]; 25 | for(int i=0;i>st[i]; 28 | } 29 | cout<<"\nSentence with each word reversed: "; 30 | reverseWord(st,n); 31 | } 32 | 33 | /* 34 | Input: 35 | Enter the number of words in a sentence: 4 36 | Enter the sentence: India is my country 37 | 38 | Output: 39 | Sentence with each word reversed: aidnI si ym yrtnuoc 40 | 41 | Time Complexity: O(n) 42 | 43 | Space Complexity:O(n) 44 | */ 45 | -------------------------------------------------------------------------------- /C-Plus-Plus/cp/search_insert_position.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. 3 | You may assume no duplicates in the array. 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | int search_insert_position(int arr[], int n, int target) { 10 | int l = 0, r = n - 1; 11 | int mid; 12 | while (l <= r) { 13 | mid = l + ((r - l) / 2); 14 | if (target > arr[mid]) 15 | l = mid + 1; 16 | else if (target < arr[mid]) 17 | r = mid - 1; 18 | else 19 | return mid; 20 | } 21 | return l; 22 | } 23 | 24 | int main() { 25 | int n; 26 | cin >> n; 27 | int arr[n]; 28 | for (int i = 0; i < n; i++) 29 | cin >> arr[i]; 30 | int target; 31 | cin >> target; 32 | int ans = search_insert_position(arr, n, target); 33 | cout << ans; 34 | return 0; 35 | } 36 | 37 | 38 | /* 39 | TIME COMPLEXITY:- O(log2n) 40 | SPACE COMPLEXITY:- O(n) 41 | 42 | OUTPUT:- 43 | 5 44 | 2 3 4 5 6 45 | 4 46 | 2 47 | */ 48 | -------------------------------------------------------------------------------- /C-Plus-Plus/cryptography/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C-Plus-Plus/cryptography/README.md -------------------------------------------------------------------------------- /C-Plus-Plus/dp/Rod_cutting_problem.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C-Plus-Plus/dp/Rod_cutting_problem.cpp -------------------------------------------------------------------------------- /C-Plus-Plus/dp/Unique_BST.cpp: -------------------------------------------------------------------------------- 1 | // unique BSTs using DP 2 | // Given n, how many structurally unique BST's that store values 1 ... n? 3 | 4 | #include 5 | using namespace std; 6 | 7 | int uniqueBST(int n) { 8 | vector count(n + 1); 9 | // for each 'i' number of nodes 10 | for (int i = 1; i <= n ; ++i) { 11 | for (int j = 0 ; j < i ; ++j) { 12 | // No. of trees if j is a root 13 | count[i] += max(count[j], 1) * max(count[i - j - 1], 1); 14 | } 15 | } 16 | return count[n]; 17 | } 18 | 19 | int main() { 20 | int n; 21 | cout << "Enter value:"; 22 | cin >> n; 23 | cout << "Number of Unique BSTs " << uniqueBST(n) << endl; 24 | 25 | return 0; 26 | } 27 | 28 | /* 29 | output: 30 | Enter value:3 31 | Number of Unique BSTs 5 32 | Time complexity : O(n) 33 | */ 34 | -------------------------------------------------------------------------------- /C-Plus-Plus/dp/Zero_N_Knapsack.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C-Plus-Plus/dp/Zero_N_Knapsack.cpp -------------------------------------------------------------------------------- /C-Plus-Plus/dp/factorial_bottom_up.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | /* 5 | Factorial is calculated using recursive formula : n! = n * (n-1)! 6 | We will initially save Factorial of 0 and 1 as 1. Then we will 7 | recursively call Factorial on the lower numbers and save its data in array 8 | */ 9 | int fac[100]; 10 | int Factorial(int n) 11 | { 12 | if(n == 0 || n == 1) 13 | return 1; 14 | 15 | fac[0] = 1; 16 | fac[1] = 1; 17 | 18 | for(int i=2 ; i<=n ; i++) 19 | { 20 | fac[i] = i * fac[i-1]; 21 | } 22 | return(fac[n]); 23 | } 24 | 25 | int main() 26 | { 27 | int n; 28 | cout<<"Enter number : "; 29 | cin>>n; 30 | cout<<"Factorial of "< 2 | using namespace std; 3 | 4 | /* 5 | Factorial is calculated using recursive formula : n! = n * (n-1)! 6 | We will initially save Factorial of 0 and 1 as 1. Then we will 7 | recursively call Factorial on the lower numbers and save its data in array 8 | */ 9 | int fac[100]; 10 | int Factorial(int n) 11 | { 12 | if(n == 0) 13 | return 1; 14 | if(n == 1) 15 | return 1; 16 | if(fac[n] != 0) 17 | return fac[n]; 18 | return (fac[n] = n * Factorial(n-1)); 19 | } 20 | 21 | int main() 22 | { 23 | int n; 24 | cout<<"Enter number : "; 25 | cin>>n; 26 | cout<<"Factorial of "< 2 | using namespace std; 3 | 4 | //space O(n) 5 | int fib(int n,int dp[]){ 6 | for(int i=2;i<=n;i++){ 7 | dp[i]=dp[i-1]+dp[i-2]; 8 | } 9 | return dp[n]; 10 | } 11 | 12 | //space O(1) 13 | int fib_Space_Opt(int n){ 14 | //base case 15 | if(n == 0 || n == 1) return n; 16 | 17 | int a = 0; 18 | int b = 1; 19 | int c; 20 | 21 | for(int i=2;i<=n;i++){ 22 | c = a + b; 23 | a = b; 24 | b = c; 25 | } 26 | return c; 27 | } 28 | 29 | 30 | int main() { 31 | int n; 32 | cout<<"Enter number 'n' to find nth fibonacci number: "; 33 | cin>>n; 34 | int dp[n+1]={0}; 35 | dp[1] = 1; 36 | 37 | cout<<"Output calculated with space complexity O(n): "; 38 | cout< 2 | using namespace std; 3 | 4 | //Recursion+Memoization 5 | int fib(int n,int dp[]){ 6 | //base case 7 | if(n == 0 || n == 1) return n; 8 | //Recursive 9 | //Look Up 10 | if(dp[n] != 0) return dp[n]; 11 | 12 | int ans; 13 | ans = fib(n-1,dp)+fib(n-2,dp); 14 | return dp[n] = ans; 15 | } 16 | 17 | 18 | int main() { 19 | int n; 20 | cin>>n; 21 | int dp[n+1]={0}; 22 | cout<<"output :"< 8 | using namespace std; 9 | 10 | void inverse(int a[], int n, int b[]) 11 | { 12 | for (int i = 0; i < n; i++) 13 | { 14 | int temp = a[i]; 15 | b[temp] = i; 16 | } 17 | for (int i = 0; i < n; i++) 18 | cout << b[i] << " "; 19 | } 20 | 21 | int main() 22 | { 23 | // Driver code begins 24 | int t, n; 25 | cin >> t; 26 | while (t--) 27 | { 28 | cin >> n; 29 | int ori[n]; 30 | int inv[n]; 31 | 32 | for (int i = 0; i < n; i++) 33 | cin >> ori[i]; 34 | 35 | inverse(ori, n, inv); 36 | } 37 | return 0; 38 | } 39 | 40 | /* 41 | time complexity -: O(n) 42 | Sample input: 43 | 2 44 | 5 45 | 4 0 2 3 1 46 | 3 47 | 0 1 2 48 | Sample Output 49 | 1 4 2 3 0 50 | 0 1 2 51 | */ 52 | 53 | -------------------------------------------------------------------------------- /C-Plus-Plus/graphs/README.md: -------------------------------------------------------------------------------- 1 | ### Graph algorithms in C++ 2 | -------------------------------------------------------------------------------- /C-Plus-Plus/heap/ConnectNRopesWithMinumumCost.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int minCost(int arr[], int n){ 5 | //Creating Priority Queue(Min Heap) 6 | priority_queue, greater > pq(arr, arr + n); 7 | int output = 0; 8 | 9 | while (pq.size() > 1) { 10 | //Getting the 2 smallest ropes; 11 | int first = pq.top(); 12 | pq.pop(); 13 | int second = pq.top(); 14 | pq.pop(); 15 | 16 | output += first + second; 17 | pq.push(first + second); 18 | } 19 | 20 | return output; 21 | } 22 | 23 | int main(){ 24 | cout<<"Enter The number of Ropes:\n"; 25 | int n; 26 | cin>>n; 27 | int ar[n]; 28 | cout<<"Enter the Cost of each rope:\n"; 29 | for(int i=0;i>ar[i]; 31 | } 32 | cout << "Minimum cost for connecting ropes is " << minCost(ar,n); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /C-Plus-Plus/math/Ackermann_function.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int Ackermann_Function(int m, int n) { 4 | if (m == 0) 5 | return n + 1; 6 | 7 | else if (m > 0 && n == 0) 8 | return Ackermann_Function(m - 1, 1); 9 | 10 | else if (m > 0 && n > 0) 11 | return Ackermann_Function(m - 1, Ackermann_Function(m, n - 1)); 12 | } 13 | 14 | int main() { 15 | int m, n; 16 | cin >> m >> n; 17 | cout << Ackermann_Function(m, n); 18 | return 0; 19 | } 20 | 21 | /* 22 | time complexity:-O(mA(m, n)) to compute A(m, n) 23 | space complexity:- O(m) to compute A(m, n) 24 | Examples:- 25 | m=1,n=2 26 | output=4 27 | m=3,n=3 28 | output=61 29 | */ 30 | -------------------------------------------------------------------------------- /C-Plus-Plus/math/Check_whether_a_number_is_power_of_2.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Given a number , check whether the number is power of 2 or not. 3 | We can check this by doing some bitwise operation. Bitwise operations are best because they perform the operation in least possible time. 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | bool number_is_power_of_2(int number) 10 | { 11 | if((number & (number - 1)) == 0) 12 | return true; 13 | return false; 14 | } 15 | int main() 16 | { 17 | cout << "Enter the number \n"; 18 | int number; 19 | cin >> number; 20 | bool solve = number_is_power_of_2(number); 21 | if(solve) 22 | cout << "The Number is power of 2\n"; 23 | else 24 | cout << "No. the number is not power of 2\n"; 25 | } 26 | /* 27 | Standard Input and Output 28 | 29 | Enter the number 30 | 64 31 | The Number is power of 2 32 | 33 | Enter the number 34 | 34 35 | No. the number is not power of 2 36 | 37 | Time Complexity : O(1) 38 | Space Complexity : O(1) 39 | 40 | */ 41 | -------------------------------------------------------------------------------- /C-Plus-Plus/math/GCD_In_C.cpp: -------------------------------------------------------------------------------- 1 | //C program to implement Euclid's Algorithm to find greatest common divisor 2 | 3 | #include 4 | 5 | // It is a recursive function that calculates greatest common divisor or hcf of 2 6 | // integer numbers a and b 7 | // GCD of two numbers is the largest number that divides both of them. 8 | // A simple way to find GCD is to factorize both numbers and multiply common factors. 9 | 10 | int gcd(int a,int b) 11 | { //base case 12 | if (a==0) 13 | return b; 14 | //recursive case 15 | else 16 | return gcd(b%a,a); 17 | } 18 | 19 | //initializing a and b. 20 | //Here a is always the smaller number and 21 | // b is always the bigger number between the two. 22 | 23 | int main() 24 | { int a = 10, b = 15; 25 | printf("GCD(%d, %d) = %d\n", a, b, gcd(a, b)); //should print 5 26 | a = 35, b = 10; 27 | printf("GCD(%d, %d) = %d\n", a, b, gcd(a, b)); //should print 5 28 | a = 31, b = 2; 29 | printf("GCD(%d, %d) = %d\n", a, b, gcd(a, b)); //should print 1 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /C-Plus-Plus/math/Hamming_Distance.cpp: -------------------------------------------------------------------------------- 1 | /* Hamming Distance 2 | ----------------- 3 | Problem: 4 | For given x and y, return the number of positions where their values differ in their binary representations as a 32-bit integer. 5 | 6 | Implementation: 7 | x = 10 (1010) and y = 6 (0110) if we apply xor to x and y the resultant ans = 12 (1100). 8 | XOR is 0 when 2 bits are equal and 1 when 2 bits contrasts 9 | Number of bits in ans = 2 10 | */ 11 | 12 | #include 13 | using namespace std; 14 | 15 | // O(N) time complexity 16 | int solve1(int x, int y) 17 | { 18 | int ans = x^y; 19 | return __builtin_popcount(ans); 20 | } 21 | 22 | // O(1) time complexity 23 | int solve2(int x, int y) 24 | { 25 | int count = 0; 26 | for (int i = 0; i < 32; i++) 27 | if ( (x & (1 << i)) != (y & (1 << i)) ) 28 | count++; 29 | return count; 30 | } 31 | int main() 32 | { 33 | int x,y; 34 | cin>>x>>y; 35 | cout< 6 | using namespace std; 7 | 8 | class Solution 9 | { 10 | public: 11 | long long squaresInChessBoard(long long n) 12 | { 13 | return (n * (n + 1) * (2 * n + 1)) / 6; 14 | } 15 | }; 16 | 17 | int main() 18 | { 19 | long long num; 20 | cout << "Enter the number : " << endl; 21 | cin >> num; 22 | 23 | Solution obj; 24 | cout << "The square is : " << endl; 25 | cout << obj.squaresInChessBoard(num) << endl; 26 | } 27 | 28 | /* 29 | Time complexity : O(N) 30 | Space complexity : O(1) 31 | */ 32 | 33 | /* 34 | Input : 35 | Enter the number : 1 36 | Output : 37 | The square is : 1 38 | */ 39 | 40 | -------------------------------------------------------------------------------- /C-Plus-Plus/math/Sum_of_digits.cpp: -------------------------------------------------------------------------------- 1 | // C++ PROGRAM TO COMPUTE THE SUM OF DIGITS OF A NUMBER 2 | 3 | #include 4 | using namespace std; 5 | 6 | // Function to calculate the sum of digits 7 | int sum_of_digits(int N) 8 | { 9 | int sum = 0; 10 | while(N != 0) 11 | { 12 | // Adding the last digit of the number to the sum 13 | int rem = N % 10; 14 | sum += rem; 15 | // Removing the last digit 16 | N = N / 10; 17 | } 18 | return sum; 19 | } 20 | 21 | int main() 22 | { 23 | int N; 24 | cout << "Enter any integer:"; 25 | cin >> N; 26 | 27 | cout << "Sum of the digits of a number:" << sum_of_digits(N) << endl; 28 | return 0; 29 | } 30 | 31 | /* 32 | Example 1: 33 | Input : N = 453 34 | Output: 12 35 | Explanation: Sum of digits of number = (4+5+3) = 12 36 | 37 | Example 2: 38 | Input : N = 101 39 | Output: 2 40 | Explanation: Sum of digits of number = (1+0+1) = 2 41 | */ 42 | -------------------------------------------------------------------------------- /C-Plus-Plus/math/catalan_num.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Catalan numbers is a number sequence, which is found useful in a number of 3 | combinatorial problems, often involving recursively-defined objects. 4 | */ 5 | 6 | #include 7 | using namespace std; 8 | 9 | // To find nth catalan number using recursive function 10 | unsigned long int catalan(unsigned int n) 11 | { 12 | 13 | if (n <= 1) 14 | return 1; 15 | unsigned long int res = 0; 16 | for (int i = 0; i < n; i++) 17 | res = res + catalan(i) * catalan(n - i - 1); 18 | 19 | return res; 20 | } 21 | 22 | int main() 23 | { 24 | cout << "Enter the Number:" << endl; 25 | int n; 26 | cin >> n; 27 | for (int i = 0; i < n; i++) 28 | { 29 | cout << catalan(i) << " "; 30 | } 31 | cout << endl; 32 | return 0; 33 | } 34 | 35 | /* 36 | Input: 37 | Enter the Number: 38 | 15 39 | Ouput: 40 | 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 742900 2674440 41 | 42 | Time Complexity: O(2^n) 43 | Space Complexity: O(1) 44 | */ -------------------------------------------------------------------------------- /C-Plus-Plus/math/factorial_space_optimized.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | /* 5 | Factorial is calculated using recursive formula : n! = n * (n-1)! 6 | Iteratively, it can be calculated by multiplying the current product 7 | by the next number. Initially current product will be 1. 8 | */ 9 | int Factorial(int n) 10 | { 11 | int prod = 1; 12 | for(int i=2 ; i<=n ; i++) 13 | { 14 | prod *= i; 15 | } 16 | return prod; 17 | } 18 | 19 | int main() 20 | { 21 | int n; 22 | cout<<"Enter number : "; 23 | cin>>n; 24 | cout<<"Factorial of "< 3 | using namespace std; 4 | 5 | int sum_of_digits(int num) 6 | { 7 | int cnt = 0; 8 | while (num != 0) 9 | { 10 | cnt++; 11 | // Removing the least significant digit 12 | num = num / 10; 13 | } 14 | return cnt; 15 | } 16 | 17 | int main() 18 | { 19 | int num, cnt; 20 | cout << "\nEnter the number: "; 21 | cin >> num; 22 | 23 | // If the number is negative, convert it into positive 24 | if (num < 0) 25 | { 26 | num = num * -1; 27 | } 28 | 29 | // Call the function 30 | cnt = sum_of_digits(num); 31 | // Print the obtained count 32 | cout << "The number of digits in the given number is: " << cnt; 33 | return 0; 34 | } 35 | 36 | /* 37 | Time Complexity- O(log(num)), where 'num' is the given num 38 | Space Complexity- O(1) 39 | 40 | SAMPLE INPUT AND OUTPUT 41 | 42 | SAMPLE 1 43 | 44 | Enter the number: 3241 45 | The number of digits in the given number is: 4 46 | */ 47 | -------------------------------------------------------------------------------- /C-Plus-Plus/math/ugly_numbers.cpp: -------------------------------------------------------------------------------- 1 | ''' 2 | Ugly numbers are numbers whose only prime factors are 2, 3 or 5. 3 | The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, … shows the first 11 ugly numbers. 4 | By convention, 1 is included. Write a program to find Nth Ugly Number. 5 | 6 | Example 1: 7 | Input: 8 | N = 10 9 | Output: 12 10 | Explanation: 10th ugly number is 12. 11 | 12 | Example 2: 13 | Input: 14 | N = 4 15 | Output: 4 16 | Explanation: 4th ugly number is 4. 17 | ''' 18 | 19 | #include 20 | using namespace std; 21 | 22 | int main() 23 | { 24 | //code 25 | int t; 26 | cin>>t; 27 | 28 | long long arr[10000]; 29 | int c2 = 0, c3 = 0, c5 = 0; 30 | arr[0] = 1; 31 | 32 | for(int i=1; i<10000; i++) 33 | { 34 | arr[i] = min(arr[c2]*2, min(arr[c3]*3, arr[c5]*5)); 35 | 36 | if(arr[i] % 2 == 0) 37 | c2++; 38 | if(arr[i] % 3 == 0) 39 | c3++; 40 | if(arr[i] % 5 == 0) 41 | c5++; 42 | } 43 | 44 | while(t>0) 45 | { 46 | int n; 47 | cin>>n; 48 | cout<" 3 | Given a string S, compute recursively a new string where identical chars that are adjacent in the original string are separated from each other by a "*". 4 | */ 5 | 6 | #include 7 | void pairStar(char input[]) { 8 | int size = 0, i; 9 | while (input[size] != '\0') 10 | size++; 11 | if (input[0] == '\0' || size == 0) 12 | return; 13 | if (input[0] == input[1]) { 14 | input[size+1] = '\0'; 15 | for (int i = size-1; i >= 1; i--) { 16 | input[i+1] = input[i]; 17 | } 18 | input[1] = '*'; 19 | pairStar(input+1); 20 | } else { 21 | pairStar(input+1); 22 | } 23 | } 24 | int main() { 25 | char input[100]; 26 | std::cin.getline(input, 100); 27 | pairStar(input); 28 | std::cout << input < 11 | using namespace std; 12 | int main() 13 | { 14 | int a, b, result = 0; 15 | 16 | cout << "Enter two numbers to multiply: \n"; 17 | cin >> a >> b; 18 | while (b > 0) 19 | { 20 | if (b % 2 != 0) 21 | { 22 | result += a; 23 | } 24 | a = a << 1; 25 | b = b >> 1; 26 | } 27 | cout << "Product: " << result; 28 | return 0; 29 | } 30 | 31 | /*Input: 32 | Enter two numbers to multiply: 33 | 4 20 34 | 35 | Output: 36 | Product: 80 37 | 38 | Time complexity: O(1) 39 | */ -------------------------------------------------------------------------------- /C-Plus-Plus/other/SwapTwoNibbles.cpp: -------------------------------------------------------------------------------- 1 | //Given a byte, swap the two nibbles in it. For example 100 is be represented as 01100100 in a byte (or 8 bits). 2 | //The two nibbles are (0110) and (0100). If we swap the two nibbles, we get 01000110 which is 70 in decimal. 3 | 4 | #include 5 | using namespace std; 6 | int main() 7 | { 8 | int swapNibbles(int n); 9 | int n, result; 10 | cout << "Enter a number: "; 11 | cin >> n; 12 | result = swapNibbles(n); 13 | cout << result; 14 | 15 | return 0; 16 | } 17 | 18 | int swapNibbles(int n) 19 | { 20 | return (((n & 0x0F) << 4) | ((n & 0xF0) >> 4)); 21 | } 22 | 23 | /* 24 | Input: 25 | Enter a number: 100 26 | 27 | Output: 28 | 70 29 | 30 | Time complexity: O(1) 31 | */ -------------------------------------------------------------------------------- /C-Plus-Plus/other/Unique_Number_III.cpp: -------------------------------------------------------------------------------- 1 | /*Unique_Number_III 2 | Given an array that contains all elements occurring 3 times, but one occurs only once. Find that unique element.*/ 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int cnt[64] = {0}; 8 | int n, no; 9 | cin >> n; 10 | for (int i = 0; i < n; i++) 11 | { 12 | cin >> no; 13 | 14 | int j = 0; 15 | while (no > 0) 16 | { 17 | int last_bit = (no & 1); 18 | cnt[j] += last_bit; 19 | j++; 20 | no = no >> 1; 21 | } 22 | } 23 | int p = 1; 24 | int ans = 0; 25 | for (int i = 0; i < 64; i++) 26 | { 27 | cnt[i] %= 3; 28 | ans += (cnt[i] * p); 29 | p = p << 1; 30 | } 31 | cout << ans << endl; 32 | return 0; 33 | } 34 | /* 35 | Input : arr[] = {6, 2, 5, 2, 2, 6, 6} 36 | Output : 5 37 | Time Complexity:O(n) 38 | */ 39 | -------------------------------------------------------------------------------- /C-Plus-Plus/other/bulb_switch_1.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Problem: Bulb Switcher - I 4 | 5 | There are n bulbs that are initially off. You first turn on 6 | all the bulbs, then you turn off every second bulb. 7 | 8 | On the third round, you toggle every third bulb (turning on 9 | if it's off or turning off if it's on). For the ith round, you 10 | toggle every i bulb. For the nth round, you only toggle the last bulb. 11 | 12 | Return the number of bulbs that are on after n rounds. 13 | 14 | */ 15 | 16 | // Code 17 | class Solution { 18 | public: 19 | int bulbSwitch(int num) { 20 | int result = sqrt(num); 21 | 22 | return result; 23 | } 24 | }; 25 | 26 | /* 27 | 28 | Input: n = 3 29 | Output: 1 30 | Explanation: At first, the three bulbs are [off, off, off]. 31 | After the first round, the three bulbs are [on, on, on]. 32 | After the second round, the three bulbs are [on, off, on]. 33 | After the third round, the three bulbs are [on, off, off]. 34 | So you should return 1 because there is only one bulb is on. 35 | 36 | */ -------------------------------------------------------------------------------- /C-Plus-Plus/other/bulb_switch_III.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Problem: Bulb Switcher - III 4 | 5 | There is a room with n bulbs, numbered from 1 to n, arranged 6 | in a row from left to right. Initially, all the bulbs are turned off. 7 | 8 | At moment k (for k from 0 to n - 1), we turn on the light[k] bulb. 9 | A bulb changes color to blue only if it is on and all the previous 10 | bulbs (to the left) are turned on too. 11 | 12 | Return the number of moments in which all turned-on bulbs are blue. 13 | 14 | */ 15 | 16 | // Code 17 | class Solution { 18 | public: 19 | int numTimesAllBlue(vector& light) { 20 | int ans = 0,pos = 0; 21 | for(int i = 0; i < light.size(); i++){ 22 | pos = max(pos, light[i]); 23 | if(pos == i + 1) 24 | ans++; 25 | } 26 | return ans; 27 | } 28 | }; 29 | 30 | /* 31 | 32 | Input: light = [4,1,2,3] 33 | Output: 1 34 | Explanation: All bulbs turned on, are blue at the moment 3 (index-0). 35 | Bulb 4th changes to blue at the moment 3. 36 | 37 | */ -------------------------------------------------------------------------------- /C-Plus-Plus/other/lcm.cpp: -------------------------------------------------------------------------------- 1 | //Using GCD, find LCM of two number. 2 | 3 | #include 4 | using namespace std; 5 | 6 | // Gcd recursive Function 7 | long long gcd(long long int x, long long int y) 8 | { 9 | if (y == 0) 10 | return x; 11 | //Rcursive function 12 | return gcd(y, x % y); 13 | } 14 | 15 | // Lcm Function 16 | long long lcm(int a, int b) 17 | { 18 | //return Lcm of two number 19 | return (a / gcd(a, b)) * b; 20 | } 21 | 22 | //main function 23 | int main() 24 | { 25 | //Input 2 numbers for Lcm 26 | int n1, n2; 27 | cout << "Enter two numbers: "; 28 | cin >> n1 >> n2; 29 | //Print output 30 | cout<<"\tOUTPUT\n"; 31 | //calling Lcm Funtion 32 | cout << lcm(n1, n2); 33 | 34 | return 0; 35 | } 36 | /*Sample Input Output 37 | 38 | Sample 1. 39 | Enter two numbers : 761457 614573 40 | 41 | OUTPUT 42 | LCM of 761457 and 614573 --> 467970912861 43 | 44 | Sample 2. 45 | Enter two numbers : 6 8 46 | 47 | OUTPUT 48 | LCM of 6 and 8 --> 24 49 | 50 | Time Complexity :O(logn) 51 | Space Complexity:O(1) 52 | 53 | */ 54 | 55 | -------------------------------------------------------------------------------- /C-Plus-Plus/search/README.md: -------------------------------------------------------------------------------- 1 | ### Searching algorithms in C++ 2 | -------------------------------------------------------------------------------- /C-Plus-Plus/sort/bucket_sort.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C-Plus-Plus/sort/bucket_sort.cpp -------------------------------------------------------------------------------- /C-Sharp/blockchain/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/cp/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/cryptography/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C-Sharp/cryptography/README.md -------------------------------------------------------------------------------- /C-Sharp/dp/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/ds/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/graphs/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/math/Finding_no_of_digits_in_an_integer.cs: -------------------------------------------------------------------------------- 1 | /* Find number of digits in an integer : 2 | This program will gives you the result in O(1) Time Complexity 3 | */ 4 | 5 | using System; 6 | 7 | class CountDigits { 8 | 9 | static int countDigit(long num) { 10 | return (int)Math.Floor(Math.Log10(num) + 1); 11 | } 12 | 13 | public static void Main() 14 | { 15 | Console.WriteLine("Enter the number: "); 16 | long num = Convert.ToInt32(Console.ReadLine()); 17 | Console.WriteLine("Number of digits= " + countDigit(num)); 18 | } 19 | } 20 | /* 21 | Sample Input/Output- 22 | Enter the number: 7890 23 | Number of digits= 4 24 | 25 | */ 26 | -------------------------------------------------------------------------------- /C-Sharp/math/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/other/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/search/BinarySearch.cs: -------------------------------------------------------------------------------- 1 | public class BinarySearch 2 | { 3 | // This search method work only on sorted array 4 | static int Search(int[] array, int element) 5 | { 6 | int left = 0; 7 | int right = array.Length - 1; 8 | 9 | while (left <= right) 10 | { 11 | int middle = left + (right - left) / 2; 12 | 13 | if (array[middle] == element) 14 | { 15 | return middle; 16 | } 17 | 18 | // If element greater than the middle element we search on the right half 19 | if (array[middle] < element) 20 | { 21 | left = middle + 1; 22 | } 23 | else 24 | { 25 | right = middle - 1; 26 | } 27 | } 28 | 29 | // element not found 30 | return -1; 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /C-Sharp/search/LinearSearch.cs: -------------------------------------------------------------------------------- 1 | public class LinearSearch 2 | { 3 | public static int Search(T[] array, T element) 4 | { 5 | for (int i = 0; i < array.Length; i++) 6 | { 7 | if (array[i].Equals(element)) 8 | { 9 | return i; 10 | } 11 | } 12 | 13 | return -1; 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /C-Sharp/search/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C-Sharp/sort/BubbleSort.cs: -------------------------------------------------------------------------------- 1 | public class BubbleSort 2 | { 3 | public static void Sort(int[] array) 4 | { 5 | for (int i = 0; i < array.Length - 1; i++) 6 | { 7 | bool noSwap = true; 8 | 9 | for (int j = 0; j < array.Length - i - 1; j++) 10 | { 11 | if (array[j] > array[j + 1]) 12 | { 13 | (array[j], array[j + 1]) = (array[j + 1], array[j]); 14 | noSwap = false; 15 | } 16 | } 17 | 18 | // if there is no swap done we stop the algo 19 | if (noSwap) 20 | { 21 | break; 22 | } 23 | } 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /C-Sharp/sort/InsertionSort.cs: -------------------------------------------------------------------------------- 1 | public class InsertionSort 2 | { 3 | public static void Sort(int[] array) 4 | { 5 | for (int i = 0; i < array.Length - 1; i++) 6 | { 7 | int minIndex = i; 8 | 9 | for (int j = i + 1; j < array.Length; j++) 10 | { 11 | if (array[j] < array[minIndex]) 12 | { 13 | minIndex = j; 14 | } 15 | } 16 | 17 | if (minIndex != i) 18 | { 19 | (array[i], array[minIndex]) = (array[minIndex], array[i]); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /C-Sharp/sort/QuickSort.cs: -------------------------------------------------------------------------------- 1 | public class QuickSort 2 | { 3 | private static int partition(int[] array, int low, int high) 4 | { 5 | int pivot = array[high]; 6 | 7 | // index of smaller element 8 | int i = (low - 1); 9 | 10 | for (int j = low; j < high; j++) 11 | { 12 | if (array[j] < pivot) 13 | { 14 | i++; 15 | (array[i], array[j]) = (array[j], array[i]); 16 | } 17 | } 18 | 19 | (array[i + 1], array[high]) = (array[high], array[i + 1]); 20 | 21 | return i + 1; 22 | } 23 | 24 | public static void quickSort(int[] array, int low, int high) 25 | { 26 | if (low < high) 27 | { 28 | int partitioningIndex = partition(array, low, high); 29 | quickSort(array, low, partitioningIndex - 1); 30 | quickSort(array, partitioningIndex + 1, high); 31 | } 32 | } 33 | 34 | 35 | public static void Sort(int[] array) 36 | { 37 | quickSort(array, 0, array.Length - 1); 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /C-Sharp/sort/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C/Bit--Manipulation/count_num_of_set_bits.c: -------------------------------------------------------------------------------- 1 | // C program to count the number of set bits in a number 2 | #include 3 | 4 | int countNumSetBits(int num) 5 | { 6 | int cnt = 0; 7 | while (num > 0) 8 | { 9 | cnt = cnt + (num & 1); 10 | num = (num >> 1); 11 | } 12 | return cnt; 13 | } 14 | 15 | int main() 16 | { 17 | int num; 18 | printf("Enter the number: "); 19 | scanf("%d", &num); 20 | int res = countNumSetBits(num); 21 | printf("The number of set bits present in the given number is %d", res); 22 | } 23 | 24 | /* 25 | Time Complexity: O(log(n)), where n is the given number 26 | Space Complexity: O(1) 27 | 28 | SAMPLE INPUT AND OUTPUT 29 | 30 | SAMPLE I 31 | 32 | Enter the number: 12354 33 | The number of set bits present in the given number is 4 34 | 35 | SAMPLE II 36 | 37 | Enter the number: 2048 38 | The number of set bits present in the given number is 1 39 | */ 40 | -------------------------------------------------------------------------------- /C/Bit--Manipulation/toggle_kth_bit.c: -------------------------------------------------------------------------------- 1 | // C program to toggle the k-th bit of a number. 2 | 3 | #include 4 | 5 | int toggle_k_bit(int n, int k) 6 | { 7 | return n ^ (1 << (k - 1)); 8 | } 9 | 10 | int main() 11 | { 12 | int n, k; 13 | 14 | printf("Enter the number: "); 15 | scanf("%d", &n); 16 | printf("Enter the value of k(where you need to toggle the k'th bit) "); 17 | scanf("%d", &k); 18 | 19 | printf("The given number, after toggling the k-th bit is %d", toggle_k_bit(n, k)); 20 | 21 | return 0; 22 | } 23 | 24 | /* 25 | Time Complexity: O(1) 26 | Space Complexity: O(1) 27 | 28 | SAMPLE INPUT AND OUTPUT 29 | 30 | SAMPLE 1 31 | Enter the number: 24 32 | Enter the value of k(where you need to toggle the k'th bit): 3 33 | The given number, after toggling the k-th bit is 28. 34 | 35 | SAMPLE 2 36 | Enter the number: 33 37 | Enter the value of k(where you need to toggle the k'th bit): 12 38 | The given number, after toggling the k-th bit is 2081. 39 | */ 40 | -------------------------------------------------------------------------------- /C/blockchain/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C/cp/Array_Mirror_Inverse.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool array_mirror_inverse(int[], int); 5 | int main() 6 | { 7 | int n; 8 | bool f; 9 | printf("Enter the size of the array:"); 10 | scanf("%d", &n); 11 | int arr[n]; 12 | printf("Enter the elements:"); 13 | for (int i = 0; i < n; ++i) 14 | { 15 | scanf("%d", &arr[i]); 16 | } 17 | 18 | f = array_mirror_inverse(arr, n); 19 | if (f) 20 | printf("The given array is mirror-inverse"); 21 | else 22 | printf("The given array is not the mirror-inverse"); 23 | } 24 | 25 | // Boolean Function which return if the array is mirror-inverse or not 26 | bool array_mirror_inverse(int arr[], int n) 27 | { 28 | bool f = true; 29 | for (int i = 0; i < n; ++i) 30 | { 31 | if (arr[arr[i]] != i) 32 | { 33 | f = false; 34 | } 35 | } 36 | 37 | return f; 38 | } 39 | 40 | /* 41 | Time Complexity: O(N) 42 | 43 | Sample Output 44 | Enter the size of the array:5 45 | Enter the elements:1 0 2 4 3 46 | The given array is mirror-inverse 47 | */ 48 | 49 | -------------------------------------------------------------------------------- /C/cp/README.md: -------------------------------------------------------------------------------- 1 |

2 |
3 | 4 | PRs Welcome 5 | GitHub pull requests 6 | GitHub issues 7 | Github All Contributors 8 |

9 | 10 | # Codes in the C language 11 | 12 | ## Competitive Programming 13 | 14 | [Kadane's Algorithm for max sum subArray](cp/Kadane's_Alogorithm.c) 15 | -------------------------------------------------------------------------------- /C/cp/bulbSwitch.c: -------------------------------------------------------------------------------- 1 | /* 2 | Bulb Swither problem 3 | 4 | There are n bulbs that are initially off. You first turn on all the bulbs, then you turn off every second bulb. 5 | On the third round, you toggle every third bulb (turning on if it's off or turning off if it's on). For the ith round, you toggle every i bulb. 6 | For the nth round, you only toggle the last bulb. 7 | 8 | Return the number of bulbs that are on after n rounds. 9 | 10 | Link to problem: https://leetcode.com/problems/bulb-switcher/ 11 | */ 12 | 13 | #include 14 | 15 | int bulbSwitch(int n) { 16 | int bulb = 1, ans = 0; 17 | //A bulb is ON if it is toggled odd times 18 | while (bulb * bulb <= n) { 19 | ans++; 20 | bulb++; 21 | } 22 | return ans; 23 | } 24 | 25 | int main() { 26 | int n; 27 | printf("Enter the no. of bulbs: \n"); 28 | scanf("%d", &n); 29 | printf("%d \n", bulbSwitch(n)); 30 | return 0; 31 | } 32 | 33 | /* 34 | Sample Input: 35 | Enter the no. of bulbs: 36 | 4 37 | Output: 38 | 2 39 | Time complexity: O(n) 40 | Space complexity: O(1) 41 | */ 42 | -------------------------------------------------------------------------------- /C/cp/possible_code_recursion.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define MAX 10 4 | 5 | void decode(char *code, char *ans, int i, int j) { 6 | // i is index of code array 7 | // j is index of ans array 8 | if (i >= strlen(code)) { 9 | printf("%s ", ans); 10 | return; 11 | } 12 | // getting all possible sequences recursives 13 | if (code[i + 1] != '0') { 14 | ans[j] = (code[i] - '0' + 96); 15 | decode(code, ans, i + 1, j + 1); 16 | } 17 | // converting a num to char 18 | if (code[i + 1]) { 19 | int result = (code[i] - '0') * 10 + (code[i + 1] - '0') - 1; 20 | if (result <= 25) { 21 | ans[j] = result + 97; 22 | ans[j + 1] = '\0'; 23 | decode(code, ans, i + 2, j + 1); 24 | } 25 | } 26 | } 27 | int main() { 28 | // creating a null string 29 | char ans[50] = { '\0' }; 30 | // input string 31 | char code[MAX]; 32 | printf("Enter the code: "); 33 | scanf("%s", code); 34 | decode(code, ans, 0, 0); 35 | } 36 | 37 | /* 38 | OUTPUT: 39 | Enter the code: 1123 40 | aabc aaw alc kbc kw 41 | Time Complexity : O(n) 42 | Space complexity : O(n) 43 | */ 44 | -------------------------------------------------------------------------------- /C/cp/sum_of_triplet.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C/cp/sum_of_triplet.c -------------------------------------------------------------------------------- /C/cryptography/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C/cryptography/README.md -------------------------------------------------------------------------------- /C/dp/README.md: -------------------------------------------------------------------------------- 1 | # Dynamic Programming 2 | 3 | - [Fibonacci Nth term](dp/Fibonacci.c) 4 | -------------------------------------------------------------------------------- /C/dp/Unique_BST.c: -------------------------------------------------------------------------------- 1 | // Unique BSTs using DP 2 | // Given n, how many structurally unique BST's that store values 1 ... n? 3 | 4 | #include 5 | 6 | int max(int num1, int num2) { 7 | return (num1 > num2) ? num1 : num2; 8 | } 9 | 10 | int uniqueBST(int n) { 11 | int count[n + 1]; 12 | for (int i = 0; i < n + 1; i++) 13 | count[i] = 0; 14 | // for each 'i' number of nodes 15 | for (int i = 1; i <= n; ++i) { 16 | for (int j = 0; j < i; ++j) { 17 | // No. of trees if j is a root 18 | count[i] += max(count[j], 1) * max(count[i - j - 1], 1); 19 | } 20 | } 21 | return count[n]; 22 | } 23 | 24 | int main() { 25 | int n; 26 | printf("Enter the number: \n"); 27 | scanf("%d", &n); 28 | int num = uniqueBST(n); 29 | printf("Number of Unique BSTs %d is: \n", num); 30 | return 0; 31 | } 32 | 33 | /* 34 | input: 35 | Enter value:3 36 | output: 37 | Number of Unique BSTs 5 38 | Time complexity : O(n^2) 39 | */ 40 | -------------------------------------------------------------------------------- /C/ds/FenwickTree.c: -------------------------------------------------------------------------------- 1 | **Fenwick Tree** 2 | 3 | #include 4 | 5 | int FWtree[100] = {0}; 6 | int SIZE; 7 | 8 | int get_sum(int i) 9 | { 10 | int sum = FWtree[i]; 11 | while(i) 12 | { 13 | i -= (i & (-i)); 14 | sum += FWtree[i]; 15 | } 16 | return sum; 17 | } 18 | 19 | void add(int i, int value) 20 | { 21 | while(i < SIZE) 22 | { 23 | FWtree[i] += value; 24 | i += (i & (-i)); 25 | } 26 | } 27 | 28 | void init_fw_tree(int my_array[], int start, int end) 29 | { 30 | SIZE = end-start+2; 31 | for(int i = 1; i <= end-start+2; i++) 32 | { 33 | add(i, my_array[ start+i-1 ]); 34 | } 35 | } 36 | 37 | int main() 38 | { 39 | int my_array[] = {1, 3, 2, 4, 5 ,9, 6, 5 ,0, 3, 4, 3, 2, 2}; 40 | init_fw_tree(my_array, 0, 13); 41 | 42 | //get sum of all the numbers in the array 43 | printf("Sum of all numbers in the array is = %d\n",get_sum(14)); 44 | 45 | // update 5th index with value 9 46 | add(5,9); 47 | printf("New sum after updating 5th index with value 8 is = %d\n",get_sum(14)); 48 | 49 | return 0; 50 | } 51 | 52 | -------------------------------------------------------------------------------- /C/ds/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C/graphs/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C/math/GCD_In_C.c: -------------------------------------------------------------------------------- 1 | /*Euclidean Algorithm for GCD 2 | GCD of two numbers is the largest number that divides both of them 3 | */ 4 | #include 5 | 6 | int Euclid_GCD(int, int); 7 | int main() 8 | { 9 | int num1, num2, gcd; 10 | printf("Enter the two numbers:"); 11 | scanf("%d %d", &num1, &num2); 12 | gcd = Euclid_GCD(num1, num2); 13 | printf("GCD=%d", gcd); 14 | return 0; 15 | } 16 | 17 | // Recursive function to show Euclidean Algorithm 18 | int Euclid_GCD(int num1, int num2) 19 | { 20 | if (num2 == 0) 21 | return num1; 22 | else 23 | return (Euclid_GCD(num2, num1 % num2)); 24 | } 25 | 26 | /* 27 | Sample Output 28 | Enter the two numbers:77 121 29 | GCD=11 30 | 31 | Complexities 32 | Time Complexity:O(logN) 33 | Space Complexity:O(1) 34 | */ 35 | 36 | -------------------------------------------------------------------------------- /C/math/Magic_Number.c: -------------------------------------------------------------------------------- 1 | // A number is said to be Magic Number, when the recursive sum of the digits is 1. 2 | #include 3 | 4 | int calsum(int); 5 | int magic_num(int); 6 | int main() 7 | { 8 | int num; 9 | printf("Enter the number to be checked:"); 10 | scanf("%d", &num); 11 | if (magic_num(num) == 1) 12 | printf("%d is a magic number", num); 13 | else 14 | printf("%d is not a magic number", num); 15 | return 0; 16 | } 17 | 18 | // Function to check if the number is a magic number or not 19 | int magic_num(int num) 20 | { 21 | int sum; 22 | while (num > 9) 23 | { 24 | sum = calsum(num); 25 | num = sum; 26 | } 27 | 28 | return num; 29 | } 30 | 31 | // Function to calculate the sum of digits 32 | int calsum(int num) 33 | { 34 | int sum = 0, rem; 35 | while (num > 0) 36 | { 37 | rem = num % 10; 38 | sum = sum + rem; 39 | num = num / 10; 40 | } 41 | 42 | return sum; 43 | } 44 | 45 | /* 46 | Sample Output 47 | Enter the number to be checked:1729 48 | 1729 is a magic number 49 | 50 | Complexities 51 | Time Complexity:O(n) 52 | Space Complexity:O(n) 53 | */ 54 | 55 | -------------------------------------------------------------------------------- /C/math/Neon_number.c: -------------------------------------------------------------------------------- 1 | /* C Program to check whether a number is Neon or not. 2 | A neon number is a number where the sum of digits of square of the number is equal to the number. 3 | */ 4 | 5 | #include 6 | #include 7 | void neon(int n) 8 | { 9 | int i, sum = 0, t = 1; 10 | t = pow(n, 2); 11 | while (t != 0) 12 | { 13 | sum = sum + (t % 10); 14 | t = t / 10; 15 | } 16 | if (sum == n) 17 | { 18 | printf("Neon number.\n"); 19 | } 20 | else 21 | { 22 | printf("Not a neon number\n"); 23 | } 24 | } 25 | int main() 26 | { 27 | int n; 28 | printf("Enter a number "); 29 | scanf("%d", &n); 30 | neon(n); 31 | } 32 | /* Sample Input/output 33 | Example 1- 34 | Enter a number 9 35 | Neon number. 36 | Example 2- 37 | Enter a number 144 38 | Not a neon number 39 | 40 | Space Complexity O(1) 41 | Time Complexity O(log(n)) 42 | */ 43 | -------------------------------------------------------------------------------- /C/math/Quadratic_Equation.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/C/math/Quadratic_Equation.c -------------------------------------------------------------------------------- /C/math/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C/math/armstrong_number.c: -------------------------------------------------------------------------------- 1 | // C Program to check whether a number is Armstrong or not 2 | 3 | #include 4 | #include 5 | 6 | void ArmstrongNumber(int n){ 7 | int num=n, rem, sum=0; 8 | 9 | // Counting number of digits 10 | int digits = (int) log10(num) + 1; 11 | 12 | while(num > 0) 13 | { 14 | rem = num % 10; 15 | sum = sum + pow(rem,digits); 16 | num = num / 10; 17 | } 18 | 19 | if(n==sum) 20 | printf("%d is an Armstrong number.",n); 21 | else 22 | printf("%d is not an Armstrong number.",n); 23 | } 24 | 25 | int main(){ 26 | int num; 27 | 28 | printf("Enter the number: "); 29 | scanf("%d",&num); 30 | 31 | ArmstrongNumber(num); 32 | 33 | return 0; 34 | } 35 | 36 | /* 37 | Sample input/output: 38 | 39 | Example 1: 40 | Enter the number: 153 41 | 153 is an Armstrong number. 42 | 43 | Example 2: 44 | Enter the number: 1094 45 | 1094 is not an Armstrong number. 46 | 47 | Time Complexity= O(log(n)) 48 | Space Complexity= O(1) 49 | */ 50 | -------------------------------------------------------------------------------- /C/math/automorphic_no.c: -------------------------------------------------------------------------------- 1 | /* 2 | C program to check whether the number is automorphic or not. 3 | Automorphic number is a number whose square ends with the original number itself 4 | */ 5 | #include 6 | 7 | int automorphic_num(int); 8 | int main() 9 | { 10 | int n, l; 11 | printf("Enter the number to check:\n"); 12 | scanf("%d", &n); 13 | l = automorphic_num(n); 14 | if (l == n) 15 | printf("\nAUTOMORPHIC NUMBER !"); 16 | else 17 | printf("\nNOT AUTOMORPHIC NUMBER !"); 18 | return 0; 19 | } 20 | 21 | // Function to check if the number is automorphic or not 22 | int automorphic_num(int n) 23 | { 24 | int s, temp, l; 25 | temp = n; 26 | s = n * n; 27 | int flag = 1; 28 | while (n != 0) 29 | { 30 | flag = flag * 10; 31 | n = n / 10; 32 | } 33 | 34 | l = s % flag; 35 | return l; 36 | } 37 | 38 | /* 39 | Sample Input-Output:1 40 | Enter the number to check: 41 | 7 42 | NOT AUTOMORPHIC NUMBER ! 43 | 44 | Sample Input-Output:2 45 | Enter the number to check: 46 | 5 47 | AUTOMORPHIC NUMBER ! 48 | 49 | Time Complexity: O(n) 50 | */ 51 | 52 | -------------------------------------------------------------------------------- /C/math/binary_to_decimal.c: -------------------------------------------------------------------------------- 1 | /* 2 | AIM - To take binary number from the user 3 | and convert it into binary number. 4 | */ 5 | #include 6 | #include 7 | 8 | /*Function decleration*/ 9 | int BinarytoDecimal (char s[]); 10 | 11 | int main() 12 | { 13 | char temp[100]; 14 | printf("Enter the binary number : "); 15 | gets(temp); 16 | printf("Decimal equivalent = %d",BinarytoDecimal(temp)); 17 | return 0; 18 | } 19 | /*Function to convert binary to decimal*/ 20 | int BinarytoDecimal (char temp[]) 21 | { 22 | int i,decimal=0; 23 | for(i=0;temp[i];i++) 24 | { 25 | if(temp[i]=='0') 26 | decimal=decimal*2+0; 27 | else 28 | decimal=decimal*2+1; 29 | } 30 | return(decimal); 31 | } 32 | 33 | /* 34 | 35 | Sample Input/Output: 36 | 37 | Enter the binary number : 1111 38 | Decimal equivalent = 15 39 | 40 | 41 | Time Complexity : O(n) 42 | Space Complexity : O(n) 43 | 44 | */ 45 | -------------------------------------------------------------------------------- /C/math/factorial.c: -------------------------------------------------------------------------------- 1 | // C Program to find the Factorial of a number 2 | #include 3 | 4 | long long unsigned int factorial(int num) 5 | { 6 | if (num == 0) 7 | return 1; 8 | return num * factorial(num - 1); 9 | } 10 | 11 | int main() 12 | { 13 | int num; 14 | printf("\nEnter the number: "); 15 | scanf("%d", &num); 16 | 17 | // Factorials are undefined for negative integers 18 | if (num < 0) 19 | { 20 | printf("Factorials are undefined for negative integers"); 21 | } 22 | 23 | // Call the function 24 | long long unsigned int fact = factorial(num); 25 | // Print the obtained factorial 26 | printf("The factorial of the given number is: %lld", fact); 27 | return 0; 28 | } 29 | 30 | /* 31 | 32 | Time Complexity- O(num), where 'num' is the given number 33 | Space Complexity- O(1) 34 | 35 | SAMPLE INPUT AND OUTPUT 36 | 37 | SAMPLE I 38 | 39 | Enter the number: 12 40 | The factorial of the given number is: 479001600 41 | 42 | */ 43 | -------------------------------------------------------------------------------- /C/math/happy_number.c: -------------------------------------------------------------------------------- 1 | //C Program to check a number is Happy Number or not. 2 | #include 3 | 4 | int happy_number(int); 5 | int main() 6 | { 7 | int n, ans; 8 | printf("Enter a number: "); 9 | scanf("%d", &n); 10 | ans = happy_number(n); 11 | if (ans == 1) 12 | printf("%d is a happy number", n); 13 | else 14 | printf("%d is not a happy number", n); 15 | return 0; 16 | } 17 | 18 | // Function to check if the number is a happy number or not 19 | int happy_number(int n) 20 | { 21 | int temp = n; 22 | int sum = 0, digit; 23 | while (sum != 1 && sum != 4) 24 | { 25 | sum = 0; 26 | while (temp != 0) 27 | { 28 | digit = temp % 10; 29 | sum += digit * digit; 30 | temp = temp / 10; 31 | } 32 | 33 | temp = sum; 34 | 35 | } 36 | 37 | return sum; 38 | } 39 | 40 | /* 41 | Sample Output: 42 | Enter a number: 32 43 | 32 is a happy number. 44 | 45 | Complexities 46 | Time Complexity:O(logn) 47 | Space Complexity:O(1) 48 | */ 49 | 50 | -------------------------------------------------------------------------------- /C/math/number_of_digits.c: -------------------------------------------------------------------------------- 1 | // C Program to find the Number of Digits of a given number 2 | #include 3 | 4 | int sum_of_digits(int num) 5 | { 6 | int cnt = 0; 7 | while (num != 0) 8 | { 9 | cnt++; 10 | // Removing the least significant digit 11 | num = num / 10; 12 | } 13 | return cnt; 14 | } 15 | 16 | int main() 17 | { 18 | int num, cnt; 19 | printf("\nEnter the number: "); 20 | scanf("%d", &num); 21 | 22 | // If the number is negative, convert it into positive 23 | if (num < 0) 24 | { 25 | num = num * -1; 26 | } 27 | 28 | // Call the function 29 | cnt = sum_of_digits(num); 30 | // Print the obtained count 31 | printf("The number of digits in the given number is: %d", cnt); 32 | return 0; 33 | } 34 | 35 | /* 36 | Time Complexity- O(log(num)), where 'num' is the given num 37 | Space Complexity- O(1) 38 | 39 | SAMPLE INPUT AND OUTPUT 40 | 41 | SAMPLE 1 42 | 43 | Enter the number: 1231 44 | The number of digits in the given number is: 4 45 | */ 46 | -------------------------------------------------------------------------------- /C/math/reverse_number.c: -------------------------------------------------------------------------------- 1 | // C program to reverse a number. 2 | #include 3 | 4 | // Function to reverse a number. 5 | int reverse(int num) 6 | { 7 | int rev = 0; 8 | while (num > 0) 9 | { 10 | rev = rev * 10; 11 | //Extract the last digit of the number. 12 | int rem = num % 10; 13 | rev = rev + rem; 14 | num = num / 10; 15 | } 16 | return rev; 17 | } 18 | 19 | int main() 20 | { 21 | int num; 22 | printf("Enter the number: "); 23 | scanf("%d", &num); 24 | int rev = reverse(num); 25 | printf("The reverse of the given number is %d.", rev); 26 | return 0; 27 | } 28 | 29 | /* 30 | Time Complexity: O(log(n)), where 'n' is the given number 31 | Space Complexity: O(1) 32 | 33 | SAMPLE INPUT AND OUTPUT 34 | 35 | SAMPLE 1 36 | Enter the number: 1234 37 | The reverse of the given number is 4321. 38 | 39 | SAMPLE 2 40 | Enter the number: 785487 41 | The reverse of the given number is 784587. 42 | */ 43 | -------------------------------------------------------------------------------- /C/math/special.c: -------------------------------------------------------------------------------- 1 | /*The program is to check whether a given number is a special number or not. 2 | A special number is a number whose all digits are 1 3 | Example-11 4 | */ 5 | 6 | #include 7 | 8 | void special(int); 9 | 10 | int main() { 11 | int num; 12 | printf("Enter a number\n"); 13 | scanf("%d",&num); 14 | /*Calling of function*/ 15 | special(num); 16 | 17 | return 0; 18 | } 19 | 20 | void special(int n) 21 | { 22 | int b,s=0,c=0; 23 | while(n!=0) 24 | { 25 | b=n%10; 26 | /*Sum of digits*/ 27 | s=s+b; 28 | /*Count of digits*/ 29 | c++; 30 | n=n/10; 31 | } 32 | /*if sum and count are equal 33 | then special number*/ 34 | if(s==c) 35 | printf("The given number is special"); 36 | else 37 | printf("The given number is not special"); 38 | } 39 | 40 | /* 41 | Time Complexity:O(n) 42 | Space Complexity:O(1) 43 | Input/Output: 44 | Enter a number 45 | 123 46 | The given number is not special 47 | */ 48 | -------------------------------------------------------------------------------- /C/other/Palindrome.c: -------------------------------------------------------------------------------- 1 | /* 2 | C Program to check whether a number is Palindrome or not 3 | An integer is a palindrome if the reverse of that number is equal to the original number. 4 | Example of Palindromes are 11,44,101,121, 5 | */ 6 | #include 7 | 8 | int reverse_num(int); 9 | int main() 10 | { 11 | int n, rev; 12 | printf("\n Enter a number:"); 13 | scanf("%d", &n); 14 | rev = reverse_num(n); 15 | if (rev == n) 16 | { 17 | printf("\n %d is a palindrome", n); 18 | } 19 | else 20 | { 21 | printf("\n %d is not a palindrome", n); 22 | } 23 | return 0; 24 | } 25 | int reverse_num(int num) 26 | { 27 | int rev = 0; 28 | int rem; 29 | while (num > 0) 30 | { 31 | rem = num % 10; 32 | rev = rev *10 + rem; 33 | num = num / 10; 34 | } 35 | return rev; 36 | } 37 | 38 | /* 39 | Sample Output 40 | Enter a number: 121 41 | 121 is a palindrome 42 | 43 | Complexities 44 | Time Complexity: O(n) 45 | Space Complexity: O(1) 46 | */ 47 | 48 | -------------------------------------------------------------------------------- /C/other/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C/other/Swap_two_nibbles.c: -------------------------------------------------------------------------------- 1 | //algorithm for swap nibbles in O(1) time complexity and O(1) space complexity 2 | 3 | #include 4 | 5 | int swapnibbles(int num) 6 | { 7 | return (((num & 0x0F) << 4) | ((num & 0xF0) >> 4)); 8 | } 9 | 10 | int main() 11 | { 12 | //taking input 13 | int num; 14 | printf(" Enter a number : \n"); 15 | scanf("%d",&num); 16 | int result = swapnibbles(num); 17 | printf("output is %d\n",result); 18 | } 19 | 20 | /* 21 | Input: 22 | Enter a number: 50 23 | Output: 24 | 35 25 | */ 26 | -------------------------------------------------------------------------------- /C/other/check_for_subsequence.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | char str1[1000] , str2[1000]; 7 | int i = 0 , j = 0; // i will point to string 1 and j will point to string 2 8 | printf(" Enter first string :\n"); 9 | scanf("%s" , str1); // str1 is substring 10 | printf(" Enter second string :\n"); 11 | scanf("%s" , str2); //str2 is full string 12 | while (i < strlen(str1) && j < strlen(str2)) 13 | { 14 | if (str1[i] == str2[j]) 15 | { 16 | i++; 17 | } 18 | j++; 19 | } 20 | 21 | if (i == strlen(str1)) 22 | { 23 | printf("Yes, str1 is substring of str2\n"); 24 | } 25 | else 26 | { 27 | printf("No, str1 is not a substring of str2\n"); 28 | } 29 | 30 | return 0; 31 | } 32 | 33 | /* 34 | Time Complexity: O(n) 35 | Space Complexity: O(1) 36 | Input: 37 | DTH SDFDTHFGB 38 | QBR EQVBA 39 | Output: 40 | Yes, str1 is substring of str2 41 | No, str1 is not substring of str2 42 | */ 43 | 44 | -------------------------------------------------------------------------------- /C/other/concatenate_two_strings.c: -------------------------------------------------------------------------------- 1 | //C Program to concatenate two strings without using the strcat() function. 2 | #include 3 | #include 4 | 5 | int main() { 6 | 7 | char str1[100], str2[100]; 8 | printf("Enter the first string:"); 9 | scanf("%s", str1); 10 | printf("Enter the second string:"); 11 | scanf("%s", str2); 12 | int length, j; 13 | 14 | length = 0; 15 | while (str1[length] != '\0') { 16 | ++length; 17 | } 18 | 19 | for (j = 0; str2[j] != '\0'; ++j, ++length) { 20 | str1[length] = str2[j]; 21 | } 22 | 23 | str1[length] = '\0'; 24 | 25 | printf("After concatenation, Final string will be:\n "); 26 | puts(str1); 27 | 28 | return 0; 29 | } 30 | 31 | /* 32 | INPUT: 33 | Enter the first string:Hello 34 | Enter the second string:World 35 | 36 | OUTPUT: 37 | After concatenation, Final string will be: 38 | HelloWorld 39 | */ -------------------------------------------------------------------------------- /C/search/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /C/sort/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Dart/maths/Factorial.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | // Calculate factorial of number 4 | int get_factorial(int number) { 5 | int count = 1; 6 | int factorial = 1; 7 | 8 | // Iterate from 1 till number 9 | while (count <= number) { 10 | factorial *= count; 11 | count++; 12 | } 13 | 14 | return factorial; 15 | } 16 | 17 | // Main Function, with driver code 18 | void main() { 19 | print("Enter a number:"); 20 | int input = int.parse(stdin.readLineSync()!); 21 | 22 | // Call factorial function 23 | int factorial = get_factorial(input); 24 | print("Factorial of $input is $factorial"); 25 | } 26 | /** 27 | * Sample input/output: 28 | * Enter a number: 29 | * 5 30 | * Factorial of 5 is 120 31 | * 32 | * Enter a number: 33 | * 12 34 | * Factorial of 12 is 479001600 35 | */ 36 | -------------------------------------------------------------------------------- /Dart/maths/NeonNumber.dart: -------------------------------------------------------------------------------- 1 | /* 2 | A number is said to be a neon number when the sum of digits of the square of the number 3 | is equal to the number itself 4 | */ 5 | import 'dart:io'; 6 | 7 | // Function to check if number is a neon number 8 | bool isNeon(int num) { 9 | int sum = 0; 10 | int square = num*num; 11 | 12 | while (square > 0) { 13 | int digit = square % 10; 14 | sum += digit; 15 | square ~/= 10; 16 | } 17 | if (sum == num) { 18 | return true; 19 | } 20 | return false; 21 | } 22 | 23 | // Main Function with driver code 24 | void main() { 25 | print("Enter a number :"); 26 | int num = int.parse(stdin.readLineSync()!); 27 | 28 | // Call function to check if number is a neon number 29 | if (isNeon(num)) { 30 | print("$num is a Neon Number"); 31 | } else { 32 | print("$num is not a Neon Number"); 33 | } 34 | } 35 | 36 | /** 37 | Space Complexity O(1) 38 | Time Complexity O(log(n)) 39 | 40 | Sample input/output: 41 | Enter a number : 42 | 9 43 | 9 is a Neon Number 44 | 45 | Enter a number : 46 | 12 47 | 12 is not a Neon Number 48 | */ 49 | -------------------------------------------------------------------------------- /Dart/maths/SumOfDigits.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | // Find sum of digits of number 4 | int sum_digits(int number) { 5 | int sum = 0; 6 | 7 | // Extract individual digits and add to sum 8 | while (number > 0) { 9 | int digit = number % 10; 10 | number ~/= 10; 11 | sum += digit; 12 | } 13 | return sum; 14 | } 15 | 16 | // Main Function, with driver code 17 | void main() { 18 | print("Enter a number:"); 19 | int input = int.parse(stdin.readLineSync()!); 20 | 21 | // Call sum of digits function 22 | int sum_of_digits = sum_digits(input); 23 | print("Sum of digits in $input is $sum_of_digits"); 24 | } 25 | /** 26 | Time Complexity: O(log(n)) 27 | Space Complexity: O(1) 28 | 29 | Enter a number: 30 | 401 31 | Sum of digits in 401 is 5 32 | 33 | Enter a number: 34 | 123 35 | Sum of digits in 123 is 6 36 | */ 37 | -------------------------------------------------------------------------------- /Dart/maths/catalan_number.dart: -------------------------------------------------------------------------------- 1 | /* 2 | Catalan numbers is a "number sequence", Its useful in a number of 3 | combinatorial problems, often involving recursively-defined objects. 4 | */ 5 | 6 | import 'dart:io'; 7 | 8 | // To find nth catalan number using recursive function 9 | int catalan(int n){ 10 | if (n <= 1) 11 | return 1; 12 | int res = 0; 13 | for (int i = 0; i < n; i++) 14 | res = res + catalan(i) * catalan(n - i - 1); 15 | 16 | return res; 17 | } 18 | 19 | int main(){ 20 | print("Enter the Number:"); 21 | int n = int.parse(stdin.readLineSync()!); 22 | for (int i = 0; i < n; i++) 23 | { 24 | stdout.write(catalan(i)); 25 | stdout.write(" "); 26 | } 27 | return 0; 28 | } 29 | 30 | /* 31 | Input: 32 | Enter the Number: 33 | 13 34 | Output: 35 | 1 1 2 5 14 42 132 429 1430 4862 16796 58786 208012 36 | 37 | Time Complexity: O(2^n) 38 | Space Complexity: O(1) 39 | */ -------------------------------------------------------------------------------- /Go/math/Binary/checkisnumberpoweroftwo.go: -------------------------------------------------------------------------------- 1 | package binary 2 | 3 | // IsPowerOfTwo This function uses the fact that powers of 2 are represented 4 | // like 10...0 in binary, and numbers one less than the power of 2 5 | // are represented like 11...1. 6 | // Therefore, using the and function: 7 | // 10...0 8 | // & 01...1 9 | // 00...0 -> 0 10 | // This is also true for 0, which is not a power of 2, for which we 11 | // have to add and extra condition. 12 | func IsPowerOfTwo(x int) bool { 13 | return x > 0 && (x&(x-1)) == 0 14 | } 15 | 16 | // IsPowerOfTwoLeftShift This function takes advantage of the fact that left shifting a number 17 | // by 1 is equivalent to multiplying by 2. For example, binary 00000001 when shifted by 3 becomes 00001000, 18 | // which in decimal system is 8 or = 2 * 2 * 2 19 | func IsPowerOfTwoLeftShift(number uint) bool { 20 | if number == 0 { 21 | return false 22 | } 23 | for p := uint(1); p > 0; p = p << 1 { 24 | if number == p { 25 | return true 26 | } 27 | } 28 | return false 29 | } 30 | -------------------------------------------------------------------------------- /Go/math/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Go/math/areas/2D/Areas2D.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | ) 7 | 8 | // Area of a Rectangle 9 | 10 | func rectangle(l, b float64) float64 { 11 | return l * b 12 | } 13 | 14 | // Area of a Square 15 | 16 | func square(l float64) float64 { 17 | return l * l 18 | } 19 | 20 | // Area of a Triangle 21 | 22 | func triangle(b, h float64) float64 { 23 | return (b * h) / 2.0 24 | } 25 | 26 | // Area of a Circle 27 | 28 | func circle(r float64) float64 { 29 | return math.Pi * math.Pow(r, 2) 30 | } 31 | 32 | // Area of a Parallelogram 33 | 34 | func parallelogram(b, h float64) float64 { 35 | return b * h 36 | } 37 | 38 | // Area of a Trapezium 39 | 40 | func trapezium(a, b, h float64) float64 { 41 | return (a + b) * h / 2.0 42 | } 43 | 44 | func main() { 45 | fmt.Println(rectangle(3.0, 5.0)) 46 | fmt.Println(square(4.0)) 47 | fmt.Println(triangle(4.0, 6.0)) 48 | fmt.Println(circle(3.5)) 49 | fmt.Println(parallelogram(4.0, 7.0)) 50 | fmt.Println(trapezium(4.0, 3.5, 6.5)) 51 | } 52 | 53 | // Time Complexity - O(1) 54 | // Space Complexity - O(1) 55 | -------------------------------------------------------------------------------- /Go/search/binary_search/binary_search.go: -------------------------------------------------------------------------------- 1 | // Binary Search in Go 2 | // Requires array to be sorted 3 | // Return index of found element else return -1 4 | package main 5 | 6 | import ( 7 | "fmt" 8 | ) 9 | 10 | func main() { 11 | arr := []int{2, 4, 6, 8, 10, 12, 14, 16, 18, 20} 12 | fmt.Printf("Array: %v\n", arr) 13 | var find int 14 | fmt.Printf("Please enter element to be found: ") 15 | fmt.Scan(&find) 16 | result := search(arr, find) 17 | fmt.Printf("Result: %d", result) 18 | } 19 | 20 | func search(list []int, item int) int { 21 | low := 0 22 | high := len(list) - 1 23 | for low <= high { 24 | middle := (low + high) / 2 25 | if list[middle] == item { 26 | return middle 27 | } else if list[middle] < item { 28 | low = middle + 1 29 | } else { 30 | high = middle - 1 31 | } 32 | } 33 | return -1 34 | } 35 | -------------------------------------------------------------------------------- /Go/search/interpolation_search/interpolation_search.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func Search(array []int, number int) int { 6 | low := 0 7 | high := len(array) - 1 8 | 9 | for { 10 | var key int 11 | var size int 12 | var first int 13 | var last int 14 | var value int 15 | 16 | first = array[low] 17 | last = array[high] 18 | 19 | if high == low { 20 | key = high 21 | } else { 22 | size = high - low 23 | value = int((float64(size-1) * (float64(number-first) / float64(last-first)))) 24 | key = low + value 25 | } 26 | if array[key] == number { 27 | return key 28 | } 29 | if array[key] > number { 30 | high = key - 1 31 | } else { 32 | low = key + 1 33 | } 34 | } 35 | } 36 | 37 | // Input 38 | 39 | func main() { 40 | items := []int{1, 16, 28, 37, 49, 52, 60, 75, 85, 99, 105} 41 | fmt.Println(Search(items, 85)) 42 | } 43 | 44 | // Output = 8 45 | 46 | // Time Complexity = O(n), Space Complexity = O(n) 47 | -------------------------------------------------------------------------------- /Go/search/linear_search/linear_search.go: -------------------------------------------------------------------------------- 1 | // Linear Search in Go 2 | // Return index of found element else return -1 3 | package main 4 | 5 | import ( 6 | "fmt" 7 | ) 8 | 9 | func main() { 10 | arr := []int{1, 5, 2, -5, 8, 4, 9, -12} 11 | fmt.Printf("Array: %v\n", arr) 12 | var find int 13 | fmt.Printf("Please enter element to be found: ") 14 | fmt.Scan(&find) 15 | result := search(arr, find) 16 | fmt.Printf("Result: %d", result) 17 | } 18 | 19 | func search(list []int, item int) int { 20 | for i := range list { 21 | if list[i] == item { 22 | return i 23 | } 24 | } 25 | return -1 26 | } 27 | -------------------------------------------------------------------------------- /Java/Algorithms/kadanes_Java.java: -------------------------------------------------------------------------------- 1 | // Java Program for Kadane's Algorithm. 2 | 3 | import java.util.*; 4 | public class kadanes_Java { 5 | 6 | public static void main(String[] args) { 7 | Scanner sc = new Scanner(System.in); 8 | int n = sc.nextInt(); 9 | int[] arr = new int[n]; 10 | int maxSoFar = Integer.MIN_VALUE; 11 | int curSum = 0; 12 | for (int i = 0; i < arr.length; i++) { 13 | arr[i] = sc.nextInt(); 14 | } 15 | for (int i = 0; i < arr.length; i++) { 16 | if (curSum + arr[i] < 0) 17 | curSum = 0; 18 | else 19 | curSum = curSum + arr[i]; 20 | if (curSum > maxSoFar) 21 | maxSoFar = curSum; 22 | } 23 | System.out.println(maxSoFar); 24 | sc.close(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java/blockchain/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Java/cp/ArmStrongRecursion.java: -------------------------------------------------------------------------------- 1 | // Checking Armstrong number with Recursion 2 | 3 | import java.util.Scanner; 4 | class ArmStrongRecursion 5 | { 6 | static int p; 7 | public static int armstrong(int i) 8 | { if(i<10) //base class 9 | return (int)(Math.pow(i,p)); 10 | else 11 | return((int)Math.pow(i%10,p)+armstrong(i/10)); 12 | } 13 | public static void main(String args[]) 14 | { 15 | Scanner sc=new Scanner(System.in); 16 | System.out.print("N = "); 17 | int n=sc.nextInt(); 18 | p=Integer.toString(n).length(); //calculating the number of digits in the number by converting it into String 19 | 20 | if(n==armstrong(n)) 21 | System.out.println(n+" is an Armstrong number"); 22 | else 23 | System.out.println(n+" is not an Armstrong number"); 24 | } 25 | } 26 | 27 | /* 28 | Sample Input and Output : 29 | N = 153 30 | 153 is an Armstrong number 31 | Space Complexity: O(1) 32 | Time Complexity : O(p) 33 | */ 34 | -------------------------------------------------------------------------------- /Java/cp/Count_Words.java: -------------------------------------------------------------------------------- 1 | /* This is a java code of finding total number of 2 | words in given string. 3 | */ 4 | import java.util.*; 5 | import java.lang.*; 6 | import java.io.*; 7 | import java.lang.String; 8 | public class count_words 9 | { 10 | public static int countWords(String str) 11 | { 12 | /* The java.util.StringTokenizer class allows 13 | you to break a string into tokens. 14 | */ 15 | StringTokenizer tokens = new StringTokenizer(str); 16 | return tokens.countTokens(); 17 | } 18 | public static void main(String[] args) 19 | { 20 | Scanner scan = new Scanner(System.in); 21 | System.out.print("Enter your string : ") 22 | String str = scan.next(); 23 | System.out.println("No of words: " + countWords(str)); 24 | } 25 | } 26 | /* 27 | Time complexity is O(n) 28 | Space complexity is O(1) 29 | 30 | Input : 31 | Enter your string : I like to contribute here 32 | 33 | Output: 34 | No of words: 5 35 | */ 36 | -------------------------------------------------------------------------------- /Java/cp/Defanged_IPv4.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Main { 3 | public static void main(String args[]) { 4 | int c = 0; 5 | Scanner sc = new Scanner(System.in); 6 | System.out.println("Enter IPv4 address"); 7 | String s = sc.next(); 8 | for (int i = 0; i < s.length(); i++) 9 | if (s.charAt(i) == '.') 10 | c++; 11 | s = s.replace(".", "[.]"); 12 | if (c == 3) 13 | System.out.println("Defanged IPv4 address : " + s); 14 | else 15 | System.out.println("Not a valid IPv4 address"); 16 | 17 | } 18 | } 19 | 20 | /* 21 | Sample Input and Output : 22 | 23 | Enter IPv4 address 24 | 1.1.1.1 25 | Defanged IPv4 address : 1[.]1[.]1[.]1 26 | Enter IPv4 address 27 | 2500.100.50.0 28 | Defanged IPv4 address : 2500[.]100[.]50[.]0 29 | Enter IPv4 address 30 | 1.1.1.1. 31 | Not a valid IPv4 address 32 | 33 | Time Complexity: O(n) where n is the length of address 34 | Space Complexity: O(1) 35 | */ 36 | -------------------------------------------------------------------------------- /Java/cp/Longest_Common_Prefix.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class Longest_Common_Prefix{ 3 | public static String LongestCommonPrefixFn(String[] strs) { 4 | if(strs.length==0){ 5 | return ""; 6 | } 7 | String st = strs[0]; 8 | for(int i=1; i 1; j--) 14 | arr[j] = arr[j] + arr[j - 1]; 15 | arr[i + 1] = arr[i]; 16 | for (int j = i + 1; j > 1; j--) 17 | arr[j] = arr[j] + arr[j - 1]; 18 | System.out.printf("%d ", arr[i + 1] - arr[i]); 19 | } 20 | } 21 | } 22 | 23 | /* 24 | Sample input and output 25 | Enter number: 7 26 | 27 | 1 2 5 14 42 132 429 28 | 29 | time complexity: O(n^2) 30 | space complexity: O(n) 31 | */ 32 | -------------------------------------------------------------------------------- /Java/math/Factorial.java: -------------------------------------------------------------------------------- 1 | /* 2 | Factorial is the product of all positive integers less than or equal to a given positive integer 3 | and denoted by that integer and an exclamation point. 4 | Thus, factorial five is written 5!, meaning 1 × 2 × 3 × 4 × 5. 5 | Factorial zero is defined as equal to 1. 6 | */ 7 | 8 | import java.util.Scanner; 9 | 10 | public class Factorial { 11 | public static void main(String[] args) { 12 | Scanner sc = new Scanner(System.in); 13 | System.out.println("Enter Number: "); 14 | int n = sc.nextInt(); 15 | System.out.println("Factorial of " +n+ " is: " + fact(n)); 16 | } 17 | public static int fact(int n){ 18 | if(n==0) 19 | return 1; 20 | 21 | return n*fact(n-1); 22 | } 23 | } 24 | 25 | /* 26 | Test Cases: 27 | Enter Number: 7 28 | Factorial of 7 is: 5040 29 | 30 | Enter Number: 0 31 | Factorial of 0 is: 1 32 | 33 | Time Complexity: O(n) 34 | Space Complexity: O(n) 35 | */ -------------------------------------------------------------------------------- /Java/math/PalindromeRecursion.java: -------------------------------------------------------------------------------- 1 | // Checking Palindrome number with Recursion 2 | 3 | import java.util.Scanner; 4 | class PalindromeRecursion 5 | { 6 | static long revNum=0; //stored reversed number 7 | public static long palindrome(long i) 8 | { if(i>0) //base class 9 | { revNum=(revNum*10)+(i%10); 10 | palindrome(i/10); 11 | } 12 | else 13 | return revNum; 14 | return revNum; 15 | } 16 | public static void main(String args[]) 17 | { 18 | Scanner sc=new Scanner(System.in); 19 | System.out.print("N = "); 20 | long n=sc.nextLong(); 21 | if(n==palindrome(n)) 22 | System.out.println(n+" is a Palindrome number"); 23 | else 24 | System.out.println(n+" is not a Palindrome number"); 25 | } 26 | } 27 | 28 | /* 29 | Sample Input and Output : 30 | N = 153 31 | 153 is not a Palindrome number 32 | Space Complexity: O(1) 33 | Time Complexity : O(i) i=Number of digits in n 34 | */ 35 | -------------------------------------------------------------------------------- /Java/math/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Java/math/Squares_in_2n_Chessboard.java: -------------------------------------------------------------------------------- 1 | /** 2 | Find total number of Squares in a N*N cheesboard. 3 | */ 4 | 5 | import java.io.*; 6 | import java.util.*; 7 | 8 | class Code{ 9 | public static void main(String args[]) throws IOException{ 10 | // taking input 11 | BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); 12 | System.out.println("Enter the num") 13 | Long num = Long.parseLong(read.readLine()); 14 | Sol obj = new Sol(); 15 | System.out.println("The square : ") 16 | System.out.println(obj.squares(num)); 17 | } 18 | } 19 | class Sol { 20 | // using maths logic 21 | static Long squares(Long n) { 22 | return (long) (n*(n+1)*(2*n+1))/6; 23 | } 24 | }; 25 | 26 | /* 27 | Time complexity : O(N) 28 | Space complexity : O(1) 29 | */ 30 | 31 | /* 32 | Input : 33 | Enter the number : 1 34 | Output : 35 | The square is : 1 36 | */ 37 | -------------------------------------------------------------------------------- /Java/math/countDigits/iterative.java: -------------------------------------------------------------------------------- 1 | /*Iterative:*/ 2 | import java.util.Scanner; 3 | 4 | public class CountDigits { 5 | 6 | public static void countdigit(int n) { 7 | int count=0; 8 | while(n!=0){ 9 | count=count+1; 10 | n=n/10; 11 | } 12 | System.out.println(count); 13 | 14 | } 15 | 16 | public static void main(String[] args) { 17 | 18 | Scanner sc=new Scanner(System.in); 19 | 20 | System.out.print("Enter a number : "); 21 | int n=sc.nextInt(); 22 | 23 | System.out.println("Number of digits in a number are : "); 24 | countdigit(n); 25 | 26 | } 27 | /* 28 | Sample Input : 29 | Enter a number : 24567 30 | 31 | Sample Output : 5 32 | 33 | */ 34 | -------------------------------------------------------------------------------- /Java/math/countDigits/recursive.java: -------------------------------------------------------------------------------- 1 | /*Recursive:*/ 2 | import java.util.Scanner; 3 | 4 | public class CountDigits { 5 | 6 | public static int countdigit(int n) { 7 | if(n==0){ 8 | return 0; 9 | } 10 | return 1 + countdigit(n/10); 11 | 12 | } 13 | 14 | public static void main(String[] args) { 15 | 16 | Scanner sc=new Scanner(System.in); 17 | 18 | System.out.print("Enter a number : "); 19 | int n=sc.nextInt(); 20 | 21 | System.out.println("Number of digits in a number are : "); 22 | System.out.println(countdigit(n)); 23 | 24 | } 25 | /* 26 | Sample Input : 27 | Enter a number : 24567 28 | 29 | Sample Output : 5 30 | 31 | */ 32 | -------------------------------------------------------------------------------- /Java/math/countDigits/stringmethod.java: -------------------------------------------------------------------------------- 1 | /*String Method:*/ 2 | import java.util.Scanner; 3 | 4 | public class CountDigits { 5 | 6 | public static int countdigit(int n) { 7 | if(n==0){ 8 | return 1; 9 | } 10 | return (Integer.toString(n).length()); 11 | } 12 | 13 | public static void main(String[] args) { 14 | 15 | Scanner sc=new Scanner(System.in); 16 | 17 | System.out.print("Enter a number : "); 18 | int n=sc.nextInt(); 19 | 20 | System.out.println("Number of digits in a number are : "); 21 | System.out.println(countdigit(n)); 22 | 23 | } 24 | } 25 | /* 26 | Sample Input : 27 | Enter a number : 24567 28 | 29 | Sample Output : 5 30 | 31 | 32 | */ 33 | -------------------------------------------------------------------------------- /Java/other/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Java/other/RecursionCount.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class RecursionCount { 4 | 5 | public static void main(String args[]) { 6 | Scanner scanner = new Scanner(System.in); 7 | System.out.println("Enter first string:"); 8 | String str1 = scanner.nextLine(); 9 | System.out.println("Enter second string:"); 10 | String str2 = scanner.nextLine(); 11 | scanner.close(); 12 | 13 | System.out.println("Number of occurrences of \"" + str2 + "\" in \"" + str1 + "\":" + countSubstring(str1, str2)); 14 | } 15 | 16 | static int countSubstring(String str1, String str2) { 17 | // recursive function 18 | if(str1.contains(str2)) { 19 | return 1 + countSubstring(str1.replaceFirst(str2, ""), str2); 20 | } else { 21 | return 0; 22 | } 23 | } 24 | } 25 | /* 26 | * Sample input/output: 27 | * Enter first string: 28 | * abcdabc 29 | * Enter second string: 30 | * abc 31 | * Number of occurrences of "abc" in "abcdabc":2 32 | * 33 | * Time complexity: O(n) 34 | */ 35 | -------------------------------------------------------------------------------- /Java/other/SwapNibbles.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | public class SwapNibbles { 4 | 5 | public static void main(String[] args) { 6 | Scanner sc = new Scanner(System.in); 7 | System.out.println("Enter a number:"); 8 | int num = sc.nextInt(); 9 | 10 | int result = swapNibbles(num); 11 | 12 | System.out.println("Number after swapping nibbles:" + result); 13 | sc.close(); 14 | } 15 | 16 | private static int swapNibbles(int x) { 17 | /* (x & 0x0F) << 4 gives us the last 4 bits of the number and 18 | shifts it by 4 bits to the left. 19 | (x & 0xF0) >> 4 gives us the last 4 bits of the number and 20 | shifts it to right by 4 bits. */ 21 | return ((x & 0x0F) << 4 | (x & 0xF0) >> 4); 22 | } 23 | } 24 | /* 25 | * Sample input/output 26 | * Enter a number: 27 | * 100 28 | * Number after swapping nibbles:70 29 | * 30 | * Space and Time complexity = O(1) 31 | */ 32 | -------------------------------------------------------------------------------- /Java/search/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Java/search/Stack_Search.java: -------------------------------------------------------------------------------- 1 | /* Stack search is a method to search an element in a stack and return the index at which its found. */ 2 | 3 | import java.util.*; 4 | 5 | public class stack_search{ 6 | 7 | public static void main(String[] args) { 8 | 9 | Scanner sc = new Scanner(System.in); 10 | //enter the no of elemnts to be there inside stack 11 | int n = sc.nextInt(); 12 | int no; 13 | Stack st = new Stack (); 14 | for(int i = 1; i <= n; i++) { 15 | no = sc.nextInt(); 16 | st.push(no); 17 | } 18 | // Displaying the Stack 19 | System.out.println("The stack is: " + st); 20 | //enter the element to be searched 21 | int item = sc.nextInt(); 22 | // Checking for the element 23 | int search = st.search(item); 24 | System.out.println(item+" is seached at index="+(n-search+1)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Java/sort/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Java/sort/SelectionSort.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class SelectionSort 3 | { 4 | public static void main(String[] args) { 5 | int indexI,arrayLength,indexJ,temp=0,minElementIndex=0; 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("Enter size of array"); 8 | arrayLength=sc.nextInt(); 9 | int array[]=new int[arrayLength]; 10 | System.out.println("Enter Elements of array"); 11 | for(indexI=0;indexIarray[indexJ]) 19 | minElementIndex=indexJ; 20 | } 21 | 22 | temp=array[indexI]; 23 | array[indexI]=array[minElementIndex]; 24 | array[minElementIndex]=temp; 25 | } 26 | 27 | for(indexI=0;indexI 0) { 16 | 17 | //extracting the last digit 18 | let rem = temp % 10; 19 | 20 | //summation 21 | sum += parseInt(rem ** n); 22 | 23 | // removing last digit from the number 24 | // convert float into integer 25 | temp = parseInt(temp / 10); 26 | } 27 | 28 | //checking for armstrong no. 29 | if (sum == number) { 30 | console.log(`${number} is an Armstrong number`); 31 | } else { 32 | console.log(`${number} is not an Armstrong number.`); 33 | } -------------------------------------------------------------------------------- /JavaScript/math/Perfect_Number.js: -------------------------------------------------------------------------------- 1 | /* 2 | Perfect number is a positive integer which is equal to the sum of its proper positive divisors. 3 | For example: 6 is the first perfect number 4 | Proper divisors of 6 are 1, 2, 3 5 | Sum of its proper divisors = 1 + 2 + 3 = 6. 6 | Hence 6 is a perfect number. 7 | */ 8 | 9 | const prompt = require("prompt-sync")({ sigint: true }); 10 | let n = +prompt("Enter a number to check whether it is a perfect number or not: "); 11 | let sum = 0; 12 | 13 | for (let i = 1; i < n; i++) 14 | { 15 | if (n % i == 0) 16 | sum += i; 17 | } 18 | 19 | if (sum == n) 20 | console.log(`${n} is a perfect number.`); 21 | else 22 | console.log(`${n} is not a perfect number.`); 23 | 24 | /* 25 | 26 | Time Complexity: O(n) 27 | Space Complexity: O(1) 28 | 29 | node JavaScript/math/Perfect_Number.js 30 | 31 | sample 1: Enter a number to check whether it is a perfect number or not: 6 32 | Output: 6 is a perfect number. 33 | 34 | sample 2: Enter a number to check whether it is a perfect number or not: 7 35 | output: 7 is not a perfect number. 36 | 37 | */ 38 | -------------------------------------------------------------------------------- /JavaScript/math/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /JavaScript/math/bin_exp.js: -------------------------------------------------------------------------------- 1 | /* 2 | Binary exponentiation (also known as exponentiation by squaring) is a trick which allows to calculate an using only O(logn) multiplications (instead of O(n) multiplications required by the naive approach). 3 | */ 4 | 5 | function binary_expo(a,b,mod) 6 | { 7 | //End Result Store Here 8 | let ans=1; 9 | while(b>0) 10 | { 11 | if(b%2!=0) 12 | { 13 | //Making the power even 14 | ans=((ans%mod)*(a%mod))%mod; 15 | //Decrease the power by 1 16 | b--; 17 | } 18 | else 19 | { 20 | //performing sqaure to reduce the power by 2 21 | a=((a%mod)*(a%mod))%mod; 22 | //reducing the power by 2. 23 | b=b/2; 24 | } 25 | } 26 | return ans; 27 | } 28 | console.log(binary_expo(2,3,10000)); 29 | //binary_expo(number 1,number 2, mod) (a^b)%mod 30 | //Time Complexity = O (log b) -------------------------------------------------------------------------------- /JavaScript/math/catalan_number.js: -------------------------------------------------------------------------------- 1 | /* 2 | Catalan numbers is a number sequence, which is found useful in a number of 3 | combinatorial problems, often involving recursively-defined objects. 4 | */ 5 | 6 | var n = prompt("Enter the number:"); 7 | 8 | var c = []; 9 | 10 | function catalan(n) { 11 | if (n == 0) return 1; 12 | if (!c[n]) { 13 | var s = 0; 14 | for (var i = 0; i < n; i++) 15 | s += catalan(i) * catalan(n - i - 1); 16 | c[n] = s; 17 | } 18 | return c[n]; 19 | } 20 | document.write("Nth Catalan Number are:") 21 | document.write("
"); 22 | for (var i = 0; i <= n; i++) { 23 | document.write(catalan(i)); 24 | document.write("
"); 25 | } 26 | 27 | /* 28 | Input: 29 | Enter the number: 30 | 15 31 | Output: 32 | Nth Catalan Number are: 33 | 1 34 | 1 35 | 2 36 | 5 37 | 14 38 | 42 39 | 132 40 | 429 41 | 1430 42 | 4862 43 | 16796 44 | 58786 45 | 208012 46 | 742900 47 | 2674440 48 | 9694845 49 | 50 | Time Complexity: O(2^n) 51 | Space Complexity: O(1) 52 | */ -------------------------------------------------------------------------------- /JavaScript/other/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /JavaScript/search/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /JavaScript/sort/BubbleSort.js: -------------------------------------------------------------------------------- 1 | /** 2 | * time complexity O(n*n) - space complexity O(1) 3 | */ 4 | 5 | function BubbleSort(arr) { 6 | for (let i = 0; i < arr.length; i++) { 7 | // outer loop 8 | let isSwapped = false; // create a boolean to keep track of whether or not there was a successful comparison made 9 | for (let j = 0; j < arr.length - 1; j++) { 10 | // inner loop 11 | if (arr[j] > arr[j + 1]) { 12 | // check if the current value is greater than next value 13 | [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]]; // Swap the current value and next value 14 | isSwapped = true; // Set swap variable to true 15 | } 16 | } 17 | if (!isSwapped) { 18 | // if there's no swap, the arr is fully sorted and can exit there, we break. 19 | break; 20 | } 21 | } 22 | 23 | return arr; // return the sorted array 24 | } 25 | 26 | console.log(BubbleSort([4, 2, 1, 3])); 27 | // output should be => [1, 2, 3, 4] 28 | 29 | console.log(BubbleSort([-4, 18, 2, 0, 6])); 30 | // output should be => [-4, 0, 2, 6, 18] 31 | -------------------------------------------------------------------------------- /JavaScript/sort/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Julia/Bit--Manipulation/count_num_of_set_bits.jl: -------------------------------------------------------------------------------- 1 | # Julia program to count the number of set bits in a number 2 | 3 | function countNumSetBits(num) 4 | cnt = 0 5 | while(num > 0) 6 | cnt = cnt + (num & 1) 7 | num = (num>>1) 8 | end 9 | return cnt 10 | end 11 | 12 | 13 | 14 | print("Enter the number: ") 15 | num = readline() 16 | num = parse(Int, num) 17 | res = countNumSetBits(num) 18 | print("The number of set bits present in the given number is $res") 19 | 20 | 21 | """ 22 | Time Complexity: O(log(n)), where n is the given number 23 | Space Complexity: O(1) 24 | 25 | SAMPLE INPUT AND OUTPUT 26 | 27 | SAMPLE I 28 | 29 | Enter the number: 12354 30 | The number of set bits present in the given number is 4 31 | 32 | SAMPLE II 33 | 34 | Enter the number: 2048 35 | The number of set bits present in the given number is 1 36 | """ 37 | -------------------------------------------------------------------------------- /Julia/Bit--Manipulation/power_of_2.jl: -------------------------------------------------------------------------------- 1 | # Julia program to check if a number is a power of two. 2 | 3 | function power_of_two(n) 4 | # 0 is not a power of 2 5 | if(n != 0) 6 | if((n & (n-1)) == false) 7 | return true 8 | end 9 | end 10 | return false 11 | end 12 | 13 | 14 | print("Enter a number: ") 15 | n = readline() 16 | n = parse(Int, n) 17 | res = power_of_two(n) 18 | if(res) 19 | print("The given number is a power of 2.") 20 | else 21 | print("The given number is not a power of 2.") 22 | end 23 | 24 | 25 | """ 26 | Time Complexity - O(1) 27 | Space Complexity - O(1) 28 | 29 | SAMPLE INPUT AND OUTPUT 30 | 31 | SAMPLE I 32 | Enter a number: 4 33 | The given number is a power of 2. 34 | 35 | SAMPLE II 36 | Enter a number: 0 37 | The given number is not a power of 2. 38 | """ 39 | -------------------------------------------------------------------------------- /Julia/Bit--Manipulation/reverse_bits.jl: -------------------------------------------------------------------------------- 1 | """ 2 | Julia program to reverse the bits of a number 3 | Given an integer, reverse its bits in its binary equivalent and 4 | print the new number obtained in its decimal form 5 | """ 6 | 7 | function reverse_bits(n) 8 | rev = 0 9 | 10 | while(n > 0) 11 | # Shift the bit of the reversed(answer) number to the right 12 | rev = rev << 1 13 | # Stores the temporary lsb of the given number 14 | rem = n & 1 15 | # Set the lsb of the answer variable with the stored value 16 | rev = rem | rev 17 | # Drops the already processed lsb of the given number 18 | n = n >> 1 19 | end 20 | return rev 21 | end 22 | 23 | print("Enter the number? ") 24 | num = readline() 25 | num = parse(Int, num) 26 | rev = reverse_bits(num) 27 | print("The bits-reversed number is: $rev") 28 | 29 | """ 30 | Time Complexity: O(n) 31 | Space Complexity: O(1) 32 | 33 | SAMPLE INPUT AND OUTPUT 34 | 35 | Enter the number? 39 36 | The bits-reversed number is: 57 37 | """ 38 | -------------------------------------------------------------------------------- /Julia/Bit--Manipulation/toggle_kth_bit.jl: -------------------------------------------------------------------------------- 1 | # Julia program to toggle the k-th bit of a number. 2 | function toggle(num, k) 3 | return (num ⊻ (1 << (k-1))) 4 | end 5 | 6 | print("Enter the number: ") 7 | num = readline() 8 | num = parse(Int, num) 9 | print("Enter the value of k(where you need to toggle the k'th bit): ") 10 | k = readline() 11 | k = parse(Int, k) 12 | new_num = toggle(num, k) 13 | println("The given number, after toggling the k-th bit is $new_num.") 14 | 15 | """ 16 | Time Complexity: O(1) 17 | Space Complexity: O(1) 18 | 19 | SAMPLE INPUT AND OUTPUT 20 | 21 | SAMPLE 1 22 | Enter the number: 24 23 | Enter the value of k(where you need to toggle the k'th bit): 3 24 | The given number, after toggling the k-th bit is 28. 25 | 26 | SAMPLE 2 27 | Enter the number: 33 28 | Enter the value of k(where you need to toggle the k'th bit): 12 29 | The given number, after toggling the k-th bit is 2081. 30 | """ 31 | -------------------------------------------------------------------------------- /Julia/cp/GCD.jl: -------------------------------------------------------------------------------- 1 | #= Finding the Greatest Common Divisor of 2 numbers using the Euclidean 2 | Formula to lessen the time complexity. 3 | =# 4 | 5 | ## Function 6 | 7 | function GCD(a, b) 8 | if (a == 0) 9 | return b 10 | end 11 | if (b == 0) 12 | return a 13 | end 14 | if (a < b) 15 | a, b = b, a 16 | end 17 | ans = a % b 18 | while (ans != 0) 19 | a = b 20 | b = ans 21 | ans = a % b 22 | end 23 | return b 24 | end 25 | 26 | ## Input 27 | 28 | a = readline() 29 | a = parse(Int64, a) 30 | b = readline() 31 | b = parse(Int64, b) 32 | 33 | ## Calling the function 34 | 35 | GCD(a, b) 36 | 37 | #= 38 | Sample Test case: 39 | Input: 40 | a = 1001 b = 2352 41 | Output: 42 | 7 43 | Time complexity: O( log (min(a,b)) ) 44 | =# 45 | -------------------------------------------------------------------------------- /Julia/cp/Maximum_subarray_sum.jl: -------------------------------------------------------------------------------- 1 | #=Given an Array you need to find the maximum sum of all the 2 | subarrays. Subarrays are consecutive elements of the array. 3 | There are a total of n*(n+1)/2 subarrays in an array with 4 | n elements. Out of all these sub arrays find the subarray with 5 | the maximum sum. Kadane's Algorithm helps us to do this in 6 | the least time complexity.=# 7 | 8 | ## Function 9 | 10 | function maxSubArray(array) 11 | best = 0 12 | sum = 0 13 | for i in array 14 | sum = max(i, sum + i) 15 | best = max(sum, best) 16 | end 17 | return best 18 | end 19 | 20 | ## Input 21 | 22 | n = readline() 23 | n = parse(Int64, n) 24 | arr = Int64[] 25 | for i = 1:n 26 | temp = readline() 27 | temp = parse(Int64, temp) 28 | push!(arr, temp) 29 | end 30 | 31 | ## Calling the function 32 | 33 | print(maxSubArray(arr)) 34 | 35 | #= 36 | Sample test case: 37 | Input: 38 | n = 5 39 | array = 2 -3 5 4 -7 40 | Output: 41 | 9 42 | 43 | Time complexity: O(N) 44 | =# 45 | -------------------------------------------------------------------------------- /Julia/cp/Prime_factorization.jl: -------------------------------------------------------------------------------- 1 | #= Given a number n, print its prime factorization. We could do it 2 | normal way which will be having time complexity of O (sqrt(N)) 3 | but we will be using Sieve to lessen the time complexity 4 | We will make a sieve to get all the prime numbers and then get the 5 | prime factorization of the number using that.=# 6 | 7 | ## Function 8 | 9 | function PrimeFactor(n) 10 | a = zeros(Int64, n) 11 | for i = 2:n 12 | a[i] = i 13 | end 14 | for i = 2:n 15 | if (a[i] == i) 16 | for j = (i*i):i:n 17 | if (a[j] == j) 18 | a[j] = i 19 | end 20 | end 21 | end 22 | end 23 | while (n != 1) 24 | println(a[n]) 25 | n = div(n, a[n]) 26 | end 27 | end 28 | 29 | ## Input 30 | 31 | n = readline() 32 | n = parse(Int64, n) 33 | 34 | #Calling the function 35 | 36 | PrimeFactor(n) 37 | 38 | #= 39 | Sample Test case 40 | Input: 41 | n = 495 42 | Output: 43 | 3 3 5 11 44 | 45 | Time Complexity: O( log N ) 46 | =# -------------------------------------------------------------------------------- /Julia/cp/Sieve_of_Eratosthenes.jl: -------------------------------------------------------------------------------- 1 | #=Given a posititve number n find all the numbers from 2 to n which 2 | are prime and print them. Sieve of Eratosthenes is an optimal approach 3 | to find the prime numbers.We get an array of length n and if the value 4 | of array at index i is zero the number i is prime.=# 5 | 6 | ## Function 7 | 8 | function primeSieve(n) 9 | a = zeros(Int64, n + 5) 10 | for i = 2:n 11 | if (a[i] == 0) 12 | for j = (i*i):i:n 13 | a[j] = 1 14 | end 15 | end 16 | end 17 | for i = 2:n 18 | if (a[i] == 0) 19 | print("$(i) ") 20 | end 21 | end 22 | end 23 | 24 | ##Input 25 | 26 | n = readline() 27 | n = parse(Int64, n) 28 | 29 | #Calling the function 30 | 31 | primeSieve(n) 32 | 33 | #= 34 | Sample test case: 35 | Input: 36 | n = 20 37 | Output: 38 | 2 3 5 7 11 13 17 19 39 | 40 | Time complexity: O( N * log(log(N)) ) 41 | =# -------------------------------------------------------------------------------- /Julia/cp/factorials.jl: -------------------------------------------------------------------------------- 1 | #=Given a number N, find its factorial using recursion. It is quite easy 2 | but we want to add recursion algorithms in Julia.=# 3 | 4 | ## Function 5 | 6 | function fact(n) 7 | if (n == 0) 8 | return 1 9 | end 10 | if (n == 1) 11 | return 1 12 | end 13 | return n * fact(n - 1) 14 | end 15 | 16 | ## Input 17 | 18 | n = readline() 19 | n = parse(Int64, n) 20 | 21 | ## Calling the Function 22 | 23 | fact(n) 24 | 25 | #= 26 | Sample Test Case: 27 | Input: 28 | n=10 29 | Output: 30 | 3628800 31 | Time complexity: O( N ) 32 | =# 33 | -------------------------------------------------------------------------------- /Julia/cp/isPowerOf2.jl: -------------------------------------------------------------------------------- 1 | #= Given a number N check if it is a power of 2 in O(1). We will be 2 | using bitwise operator to get the calculation.=# 3 | 4 | ## Function 5 | 6 | function isPowerOfTwo(n) 7 | return (n & (n - 1) == 0) 8 | end 9 | 10 | ## Input 11 | 12 | println("Enter the number : ") 13 | n = readline() 14 | n = parse(Int64, n) 15 | 16 | ## Calling the function 17 | 18 | if (isPowerOfTwo(n)) 19 | println("Its a power of 2") 20 | else 21 | println("Its not a power of 2") 22 | end 23 | 24 | #= 25 | Sample Test Case 26 | Input: 27 | Enter a number : 4294967296 28 | Output: 29 | Its a power of 2 30 | Time complexity: O( 1 ) 31 | =# 32 | -------------------------------------------------------------------------------- /Julia/cp/subsequence.jl: -------------------------------------------------------------------------------- 1 | #= Print all the subsequences of the string. 2 | =# 3 | 4 | ## Function 5 | 6 | function subsequence(s, ans) 7 | if (length(s) == 0) 8 | if (length(ans) >= 1) 9 | println(ans) 10 | end 11 | return 12 | end 13 | ch = s[1] 14 | rest_of_string = SubString(s, 2) 15 | subsequence(rest_of_string, ans) 16 | subsequence(rest_of_string, ans * ch) 17 | end 18 | 19 | ## Input 20 | 21 | println("Enter the string: ") 22 | s = readline() 23 | 24 | ## Calling the Function 25 | 26 | println("The subsequences are :") 27 | subsequence(s, "") 28 | 29 | #= 30 | Sample Test Case: 31 | Input: 32 | Enter the string: abc 33 | Output: 34 | The subsequences are : 35 | c 36 | b 37 | bc 38 | a 39 | ac 40 | ab 41 | abc 42 | Time complexity: O ( 2^N * l) (where l is the length of string) 43 | =# 44 | -------------------------------------------------------------------------------- /Julia/dp/fibonacci.jl: -------------------------------------------------------------------------------- 1 | #= Finding the Nth number in the Fibonacci Sequence using Dynamic Programming 2 | =# 3 | 4 | ## Function 5 | 6 | function fibonacci(n) 7 | f = Int64[] 8 | push!(f, 0) 9 | push!(f, 1) 10 | for i = 3:n 11 | temp = f[i-1] + f[i-2] 12 | push!(f, temp) 13 | end 14 | return f[n] 15 | end 16 | 17 | ## Input 18 | 19 | print("Enter the number: ") 20 | n = readline() 21 | n = parse(Int64, n) 22 | println("The $(n)th fibonacci number is ") 23 | 24 | ## Calling the function 25 | 26 | fibonacci(n) 27 | 28 | #= 29 | Sample Test Case: 30 | Input: 31 | Enter the number: 5 32 | Output: 33 | The 5th fibonacci number is 3 34 | 35 | Time Complexity: O ( N ) 36 | =# 37 | -------------------------------------------------------------------------------- /Julia/math/neon_number.jl: -------------------------------------------------------------------------------- 1 | """Julia program to check if a number is a Neon Number or not 2 | A neon number is a number where the sum of digits of square of the number is equal to the number. 3 | """ 4 | 5 | function check_neon_num(n) 6 | sum = 0 7 | temp = n ^ 2 8 | while(temp != 0) 9 | sum = sum + (temp % 10) 10 | temp = temp ÷ 10 11 | end 12 | if(sum == n) 13 | return true 14 | else 15 | return false 16 | end 17 | end 18 | 19 | 20 | print("Enter the number: ") 21 | n = readline() 22 | n = parse(Int, n) 23 | res = check_neon_num(n) 24 | if res 25 | println("The given number $n is a Neon Number.") 26 | else 27 | println("The given number $n is not a Neon Number.") 28 | end 29 | 30 | 31 | """ 32 | Time Complexity: O(log(num)), where 'num' is the given number 33 | Space Complexity: O(1) 34 | 35 | SAMPLE INPUT AND OUTPUT 36 | 37 | SAMPLE 1 38 | Enter the number: 0 39 | The given number 0 is a Neon Number.. 40 | 41 | SAMPLE 2 42 | Enter the number: 14 43 | The given number 14 is not a Neon Number. 44 | 45 | """ 46 | -------------------------------------------------------------------------------- /Julia/math/number_of_digits.jl: -------------------------------------------------------------------------------- 1 | # Julia program to Find the Number of Digits in a Number 2 | 3 | # Extracting the number of digits 4 | function number_of_digits(num) 5 | count = 0 6 | while(num != 0) 7 | count = count + 1 8 | num = num ÷ 10 9 | end 10 | return count 11 | end 12 | 13 | print("Enter the number: ") 14 | num = readline() 15 | num = parse(Int, num) 16 | count = number_of_digits(abs(num)) 17 | println("The number of digits in the given number is $count.") 18 | 19 | """ 20 | Time Complexity: O(log(num)), where 'num' is the length of the given number 21 | Space Complexity: O(1) 22 | SAMPLE INPUT AND OUTPUT 23 | SAMPLE 1 24 | Enter the number: -12 25 | The number of digits in the given number is 3. 26 | SAMPLE 2 27 | Enter the number: 43258 28 | The number of digits in the given number is 22. 29 | """ 30 | -------------------------------------------------------------------------------- /Julia/math/pronic_number.jl: -------------------------------------------------------------------------------- 1 | """ 2 | Julia program to check if a number is a pronic number 3 | Pronic Numbers are those numbers that can be arranged to form a rectangle. 4 | It is a number which is the product of two consecutive integer 5 | """ 6 | 7 | function check_pronic(x) 8 | i = 0 9 | while(i <= isqrt(x)) 10 | if(x == i * (i + 1)) 11 | return true 12 | end 13 | i = i + 1 14 | end 15 | return false 16 | end 17 | 18 | 19 | print("Enter the number: ") 20 | n = readline() 21 | n = parse(Int, n) 22 | res = check_pronic(abs(n)) 23 | if(res) 24 | print("The given number $n is a pronic number.") 25 | else 26 | print("The given number $n is not a pronic number.") 27 | end 28 | 29 | 30 | """ 31 | Time Complexity: O(log(n)), where 'n' is the given number 32 | Space Complexity: O(1) 33 | 34 | SAMPLE INPUT AND OUTPUT 35 | 36 | SAMPLE 1 37 | 38 | Enter the number: 154 39 | The given number 154 is not a pronic number. 40 | 41 | SAMPLE 2 42 | Enter the number: 72 43 | The given number 72 is a pronic number. 44 | """ 45 | -------------------------------------------------------------------------------- /Julia/math/reverse_number.jl: -------------------------------------------------------------------------------- 1 | # Julia program to reverse a number 2 | 3 | # Function to reverse a number. 4 | function reverse(num) 5 | rev = 0 6 | while(num > 0) 7 | # Extract the last digit of num and add it to rev 8 | rev = rev * 10 + num %10 9 | num = num ÷ 10 10 | end 11 | return rev 12 | end 13 | 14 | print("Enter the number: ") 15 | num = readline() 16 | num = parse(Int, num) 17 | rev = reverse(num) 18 | println("The reverse of the given number is $rev.") 19 | 20 | 21 | """ 22 | Time Complexity: O(log(n)), where 'n' is the given number 23 | Space Complexity: O(1) 24 | 25 | SAMPLE INPUT AND OUTPUT 26 | 27 | SAMPLE 1 28 | Enter the number: 1234 29 | The reverse of the given number is 4321. 30 | 31 | SAMPLE 2 32 | Enter the number: 785487 33 | The reverse of the given number is 784587. 34 | """ 35 | -------------------------------------------------------------------------------- /Julia/math/sum_of_digits.jl: -------------------------------------------------------------------------------- 1 | # Julia program to Find the Sum of Digits of a Number 2 | 3 | # Extracting Each digits 4 | function sum_of_digits(num) 5 | sum = 0 6 | while(num != 0) 7 | sum = sum + (num % 10) 8 | num = num ÷ 10 9 | end 10 | return sum 11 | end 12 | 13 | print("Enter the number: ") 14 | num = readline() 15 | num = parse(Int, num) 16 | sum = sum_of_digits(abs(num)) 17 | println("The sum of digits of the given number is $sum.") 18 | 19 | """ 20 | Time Complexity: O(log(num)), where 'num' is the length of the given number 21 | Space Complexity: O(1) 22 | 23 | SAMPLE INPUT AND OUTPUT 24 | 25 | SAMPLE 1 26 | Enter the number: -12 27 | The sum of digits of the given number is 3. 28 | 29 | SAMPLE 2 30 | Enter the number: 43258 31 | The sum of digits of the given number is 22. 32 | 33 | """ 34 | -------------------------------------------------------------------------------- /Julia/math/sum_of_divisors.jl: -------------------------------------------------------------------------------- 1 | # Julia program to find the sum of divisors of a number. 2 | 3 | function sum_of_divisors(num) 4 | i = 1 5 | sum = 0 6 | while (i <= sqrt(num)) 7 | if num % i == 0 && i == sqrt(num) 8 | sum = sum + i 9 | elseif num % i == 0 10 | sum = sum + i 11 | sum = sum + (num ÷ i) 12 | end 13 | i = i + 1 14 | end 15 | return sum 16 | end 17 | 18 | 19 | print("Enter the number: ") 20 | num = readline() 21 | num = parse(Int, num) 22 | sum = sum_of_divisors(num) 23 | print("The Sum of the Divisors of the given number is $sum.") 24 | 25 | """ 26 | Time Complexity - O(n^(0.5)), where 'n' given is the number 27 | Space Complexity - O(1) 28 | 29 | SAMPLE INPUT AND OUTPUT 30 | 31 | SAMPLE I 32 | 33 | Enter the number: 256 34 | The Sum of the Divisors of the given number is 511. 35 | 36 | SAMPLE II 37 | 38 | Enter the number: 5687 39 | The Sum of the Divisors of the given number is 6384. 40 | """ 41 | -------------------------------------------------------------------------------- /Julia/math/towerOfHanoi.jl: -------------------------------------------------------------------------------- 1 | #= The famous Tower of Hanoi question where there are 3 towers with discs in them. You need 2 | to transfer all the discs from A to C =# 3 | 4 | ## Function 5 | 6 | function towerOfHanoi(discs, source = "A", destination = "C", helper = "B") 7 | if (discs == 0) 8 | return 9 | end 10 | towerOfHanoi(discs - 1, source, helper, destination) 11 | println("Move from $(source) to $(destination)") 12 | towerOfHanoi(discs - 1, helper, destination, source) 13 | end 14 | 15 | ## Input 16 | 17 | println("Enter the number of discs: ") 18 | n = readline() 19 | n = parse(Int64, n) 20 | 21 | ## Calling the function 22 | 23 | towerOfHanoi(n) 24 | 25 | #= 26 | Sample Test Case: 27 | Input: 28 | Enter the number of discs: 3 29 | Output: 30 | Move from A to C 31 | Move from A to B 32 | Move from C to B 33 | Move from A to C 34 | Move from B to A 35 | Move from B to C 36 | Move from A to C 37 | Time complexity: O(2^N) 38 | =# 39 | -------------------------------------------------------------------------------- /Kotlin/Maths/Areas2D.kt: -------------------------------------------------------------------------------- 1 | package kotlin.math 2 | 3 | // Area of a Square 4 | 5 | fun square(a: Double): Double { 6 | return a * a 7 | } 8 | 9 | // Area of a Reactangle 10 | 11 | fun rectangle(l: Double, b: Double): Double{ 12 | return l * b 13 | } 14 | 15 | // Area of a Circle 16 | 17 | fun circle(r: Double): Double{ 18 | return PI * r * r 19 | } 20 | 21 | // Area of a Triangle 22 | 23 | fun triangle(b: Double, h: Double): Double{ 24 | return b * h/2.0 25 | } 26 | 27 | // Area of a Parallelogram 28 | 29 | fun parallelogram(b: Double, h: Double): Double{ 30 | return b * h 31 | } 32 | 33 | // Area of a Trapezium 34 | 35 | fun trapezium(a: Double, b:Double, h:Double): Double{ 36 | return (a+b)*h/2.0 37 | } 38 | 39 | 40 | fun main() { 41 | println(square(2.0)) 42 | println(rectangle(2.0, 4.6)) 43 | println(circle(5.0)) 44 | println(triangle(2.0,3.0)) 45 | println(parallelogram(4.5,2.3)) 46 | println(trapezium(1.5,4.5,6.0)) 47 | } 48 | 49 | 50 | // Time Complexity - O(n) 51 | // Space Complexity - O(n) 52 | -------------------------------------------------------------------------------- /Kotlin/Maths/Factorial.kt: -------------------------------------------------------------------------------- 1 | /* 2 | The factorial of a positive number n is given by: 3 | factorial of n (n!) = 1 * 2 * 3 * 4 * ... * n 4 | */ 5 | 6 | import java.util.Scanner 7 | 8 | fun main(args: Array) { 9 | 10 | val reader = Scanner(System.`in`) 11 | print("Enter any number: ") 12 | var num :Int = reader.nextInt() 13 | 14 | var factorial: Long = 1 15 | for (i in 1..num) { 16 | // factorial = factorial * i; 17 | factorial *= i.toLong() 18 | } 19 | println("Factorial of $num = $factorial") 20 | } 21 | 22 | /* 23 | Sample Test case: 24 | Enter any number: 10 25 | Factorial of 10 = 3628800 26 | */ 27 | 28 | /* 29 | Time Complexity : O(n) 30 | Auxiliary Space : O(1) 31 | */ 32 | 33 | -------------------------------------------------------------------------------- /Kotlin/Maths/FibonacciNumber.kt: -------------------------------------------------------------------------------- 1 | /* 2 | The Fibonacci series is a series where the next term is the sum of pervious two terms. 3 | The first two terms of the Fibonacci sequence is 0 followed by 1. 4 | 5 | The Fibonacci sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, ... 6 | */ 7 | import java.util.Scanner 8 | 9 | fun main(args: Array) { 10 | 11 | val reader = Scanner(System.`in`) 12 | print("Enter any number: ") 13 | var number :Int = reader.nextInt() 14 | 15 | var index = 1 16 | var term1 = 0 17 | var term2 = 1 18 | 19 | print("Fibonacci series upto $number : ") 20 | 21 | while (index <= number) { 22 | print("$term1 , ") 23 | 24 | val sum = term1 + term2 25 | term1 = term2 26 | term2 = sum 27 | 28 | index++ 29 | } 30 | } 31 | 32 | /* 33 | Sample Test case: 34 | Enter any number: 5 35 | Fibonacci series upto 5: 0 , 1 , 1 , 2 , 3 36 | */ 37 | 38 | /* 39 | Time Complexity : O(n) 40 | Auxiliary Space : O(1) 41 | */ 42 | 43 | -------------------------------------------------------------------------------- /Kotlin/Maths/PalindromeNumber.kt: -------------------------------------------------------------------------------- 1 | //A palindromic number is a number that remains the same when its digits are reversed 2 | 3 | import java.util.* 4 | 5 | //Function to check Palindrome Number 6 | fun isPalindrome(number: Int): Boolean { 7 | var isPalindromeNumber = false 8 | var sum = 0 9 | var tempNum = number 10 | 11 | while (tempNum > 0) { 12 | val r = tempNum % 10 13 | sum = sum * 10 + r 14 | tempNum /= 10 15 | } 16 | if (sum == number) { 17 | isPalindromeNumber = true 18 | } 19 | return isPalindromeNumber 20 | } 21 | 22 | //Main Function, Entry Point of Program 23 | fun main(arg: Array) { 24 | val sc = Scanner(System.`in`) 25 | 26 | // Input Number 27 | println("Enter Number : ") 28 | val num: Int = sc.nextInt() 29 | 30 | //Call Function to check Number 31 | if (isPalindrome(num)) 32 | println("$num is a Palindrome Number") 33 | else 34 | println("$num is not a Palindrome Number") 35 | } 36 | 37 | /*Sample Test Case: 38 | Enter Number : 39 | 12321 40 | 12321 is a Palindrome Number 41 | */ 42 | -------------------------------------------------------------------------------- /Kotlin/cp/ReverseString.kt: -------------------------------------------------------------------------------- 1 | /* Program to reverse a given sentence using a recursive loop in Kotlin 2 | We will create a recursive function and operate it till the end and store the reverse order. 3 | */ 4 | 5 | 6 | import java.util.Scanner 7 | 8 | fun main(args: Array) { 9 | 10 | val reader = Scanner(System.`in`) 11 | print("Enter any sentence: ") 12 | var sentence :String = reader.nextString() 13 | 14 | val reversed = reverse(sentence) 15 | println("The reversed sentence is: $reversed") 16 | } 17 | 18 | fun reverse(sentence: String): String { 19 | if (sentence.isEmpty()) 20 | return sentence 21 | 22 | return reverse(sentence.substring(1)) + sentence[0] 23 | } 24 | 25 | /* 26 | Sample Test case: 27 | Enter any sentence: Hello Kotlin 28 | The reversed sentence is : niltoK olleH 29 | */ 30 | 31 | /* 32 | Time Complexity : O(n) 33 | Auxiliary Space : O(1) 34 | */ 35 | 36 | -------------------------------------------------------------------------------- /LOGO/Logo1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/LOGO/Logo1.png -------------------------------------------------------------------------------- /LOGO/Logo3.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/LOGO/Logo3.jpeg -------------------------------------------------------------------------------- /LOGO/logo2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/LOGO/logo2.png -------------------------------------------------------------------------------- /PHP/readme.md: -------------------------------------------------------------------------------- 1 |

2 |
3 | 4 | PRs Welcome 5 | GitHub pull requests 6 | GitHub issues 7 | Github All Contributors 8 |

9 | 10 | # Codes in the PHP language 11 | 12 | ## Sorting Algorithms 13 | 14 | - [Insertion Sort](sort/InsertionSort.php) 15 | - [Selection Sort](sort/SelectionSort.php) 16 | - [Quick Sort](sort/quick_sort.php) 17 | - [Bubble Sort](sort/bubble_sort.php) -------------------------------------------------------------------------------- /Python/Bit--Manipulation/count_num_of_set_bits.py: -------------------------------------------------------------------------------- 1 | # Python program to count the number of set bits in a number 2 | 3 | def countNumSetBits(num): 4 | cnt = 0 5 | while(num > 0): 6 | cnt = cnt + (num & 1) 7 | num = (num >> 1) 8 | return cnt 9 | 10 | 11 | if __name__ == '__main__': 12 | print("Enter the number: ") 13 | num = int(input()) 14 | res = countNumSetBits(num) 15 | print("The number of set bits present in the given number is $res") 16 | 17 | 18 | """ 19 | Time Complexity: O(log(n)), where n is the given number 20 | Space Complexity: O(1) 21 | 22 | SAMPLE INPUT AND OUTPUT 23 | 24 | SAMPLE I 25 | 26 | Enter the number: 12354 27 | The number of set bits present in the given number is 4 28 | 29 | SAMPLE II 30 | 31 | Enter the number: 2048 32 | The number of set bits present in the given number is 1 33 | """ 34 | -------------------------------------------------------------------------------- /Python/Bit--Manipulation/reverse_bits.py: -------------------------------------------------------------------------------- 1 | """ 2 | Python program to reverse the bits of a number 3 | Given an integer, reverse its bits in its binary equivalent and 4 | print the new number obtained in its decimal form 5 | """ 6 | 7 | 8 | def reverse_bits(n): 9 | rev = 0 10 | 11 | while(n > 0): 12 | # Shift the bit of the reversed(answer) number to the right 13 | rev = rev << 1 14 | # Stores the temporary lsb of the given number 15 | rem = n & 1 16 | # Set the lsb of the answer variable with the stored value 17 | rev = rem | rev 18 | # Drops the already processed lsb of the given number 19 | n = n >> 1 20 | return rev 21 | 22 | 23 | if __name__ == '__main__': 24 | print("Enter the number? ", end="") 25 | num = int(input()) 26 | rev = reverse_bits(num) 27 | print("The bits-reversed number is: {}".format(rev)) 28 | 29 | """ 30 | Time Complexity: O(n) 31 | Space Complexity: O(1) 32 | 33 | SAMPLE INPUT AND OUTPUT 34 | 35 | Enter the number? 39 36 | The bits-reversed number is: 57 37 | """ 38 | -------------------------------------------------------------------------------- /Python/Bit--Manipulation/toggle_kth_bit.py: -------------------------------------------------------------------------------- 1 | # Python program to toggle the k-th bit of a number. 2 | def toggle(num, k): 3 | return (num ^ (1 << (k-1))) 4 | 5 | 6 | if __name__ == '__main__': 7 | print("Enter the number: ", end="") 8 | n = int(input()) 9 | print("Enter the value of k(where you need to toggle the k'th bit): ", end="") 10 | b = int(input()) 11 | res = toggle(n, b) 12 | print("The given number, after toggling the k-th bit is {}".format(res)) 13 | 14 | """ 15 | Time Complexity: O(1) 16 | Space Complexity: O(1) 17 | 18 | SAMPLE INPUT AND OUTPUT 19 | 20 | SAMPLE 1 21 | Enter the number: 24 22 | Enter the value of k(where you need to toggle the k'th bit): 3 23 | The given number, after toggling the k-th bit is 28. 24 | 25 | SAMPLE 2 26 | Enter the number: 33 27 | Enter the value of k(where you need to toggle the k'th bit): 12 28 | The given number, after toggling the k-th bit is 2081. 29 | """ 30 | -------------------------------------------------------------------------------- /Python/blockchain/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Python/cp/LetterCount.py: -------------------------------------------------------------------------------- 1 | """ 2 | The program uses dictionary in python 3 | to count the number of occurence a letter 4 | makes in a word 5 | """ 6 | 7 | 8 | def LetterCount(word): 9 | dict = {} 10 | 11 | for c in word: 12 | co = dict.get(c, 0) 13 | if co == 0: 14 | dict[c] = 1 15 | else: 16 | dict[c] = co + 1 17 | 18 | return(dict) 19 | 20 | if __name__ == '__main__': 21 | word = input("enter a word ").lower() 22 | LetterCount = LetterCount(word) 23 | print(LetterCount) 24 | 25 | 26 | """ 27 | Sample Input-output 28 | enter a word aayuhsi 29 | {'a': 2, 'y': 1, 'u': 1, 'h': 1, 's': 1, 'i': 1} 30 | """ 31 | 32 | """ 33 | Time complexity- O(n) 34 | 35 | """ 36 | -------------------------------------------------------------------------------- /Python/cp/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Python/cp/Run_Length_Encoding.py: -------------------------------------------------------------------------------- 1 | def encode(s): 2 | 3 | j = 0 4 | #lenght of the input string 5 | length = len(s) 6 | 7 | while (j < length- 1): 8 | 9 | # counter for keeping the track of character 10 | counter = 1 11 | while (j < length - 1 and s[j] == s[j + 1]): 12 | counter += 1 13 | j += 1 14 | j += 1 15 | # printing the encoded value 16 | print(s[j - 1] + str(counter), end = " ") 17 | 18 | 19 | s = input("Enter the string to encode \n") 20 | print("Encoded string") 21 | encode(s) 22 | 23 | ''' 24 | Time complexity : O(N) 25 | Space complexity O(1) 26 | ''' 27 | 28 | ''' 29 | Test Case : 30 | Input : 31 | Enter the string to encode 32 | tttyyss 33 | Output : 34 | Encoded string 35 | t3 y2 s2 36 | ''' -------------------------------------------------------------------------------- /Python/cp/Sort_An_Arrayof0s1sand2s.py: -------------------------------------------------------------------------------- 1 | def sort012(arr,n): 2 | listofZero = [] 3 | listofOne = [] 4 | listofTwo = [] 5 | 6 | for i in range(0,n): 7 | if arr[i] == 0: 8 | listofZero.append(0) 9 | elif arr[i] == 1: 10 | listofOne.append(1) 11 | else: 12 | listofTwo.append(2) 13 | 14 | Total = listofZero+listofOne+listofTwo 15 | return Total 16 | 17 | 18 | 19 | 20 | arr = list(map(int,input("Enter the Number:\n").split())) 21 | n = len(arr) 22 | print(sort012(arr,n)) 23 | 24 | ''' 25 | Time Complexity is O(n) 26 | Space Complexity is O(1) 27 | 28 | Input: 29 | Enter the Number: 30 | 0 2 1 2 0 31 | 32 | Output: 33 | 0 0 1 2 2 34 | Explanation: 35 | 0s 1s and 2s are segregated 36 | into ascending order. 37 | ''' -------------------------------------------------------------------------------- /Python/cp/VowelsConsants.py: -------------------------------------------------------------------------------- 1 | ''' 2 | 3 | The program helps to count the number of 4 | vowels and consants in a string. 5 | 6 | ''' 7 | 8 | def Count(word): 9 | vc, cc = 0, 0 10 | 11 | for s in word: 12 | if (s.isalpha()): 13 | if (s == 'a' or s == 'e' or s == 'i' or s == 'o' or s == 'u'): 14 | vc = vc + 1 15 | else: 16 | cc = cc + 1 17 | return vc, cc 18 | 19 | if __name__ == "__main__": 20 | TheWord = input("Enter a string: ").lower() 21 | vc, cc = Count(TheWord) 22 | print("Vowel count = ", vc, " Consonant count = ", cc) 23 | 24 | else: 25 | print("File one executed when imported") 26 | 27 | 28 | """ 29 | Time Complexity: O(n) 30 | 31 | Sample Input: 32 | Enter a string: Hello World 33 | 34 | Sample Output: 35 | Vowel count = 3 Consonant count = 7 36 | """ 37 | -------------------------------------------------------------------------------- /Python/cp/adjacent_elements_product.py: -------------------------------------------------------------------------------- 1 | """ 2 | When given a list of integers, 3 | we have to find the pair of adjacent 4 | elements that have the largest product 5 | and return that product. 6 | """ 7 | 8 | 9 | def MaxAdjacentProduct(intList): 10 | max = intList[0]*intList[1] 11 | a = 0 12 | b = 1 13 | for i in range(1, len(intList) - 1): 14 | if(intList[i]*intList[i+1] > max): 15 | a = i 16 | b = i+1 17 | max = intList[i]*intList[i+1] 18 | return(a, b, max) 19 | 20 | if __name__ == '__main__': 21 | intList = list(map(int, input("\nEnter the numbers : ").strip().split())) 22 | pos1, pos2, max = MaxAdjacentProduct(intList) 23 | print("Max= ", max, " product of elements at position ", pos1, ",", pos2) 24 | 25 | """ 26 | Sample Input - Output: 27 | 28 | Enter the numbers : -5 -3 -2 29 | Max= 15 product of elements at position 0 , 1 30 | 31 | Time Complexity : O(n) 32 | Space Complexity : O(1) 33 | 34 | """ 35 | -------------------------------------------------------------------------------- /Python/cp/bulb_switcher.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Bulb switcher problem 3 | 4 | There are n bulbs that are initially off. 5 | You first turn on all the bulbs,then you turn off every second bulb. 6 | On the third round,toggle every third bulb (turn on if it's off or vice-versa) 7 | For the ith round, you toggle every i bulb. 8 | For the nth round, you only toggle the last bulb. 9 | Return the number of bulbs that are on after n rounds. 10 | 11 | Approach : By observation, a bulb is ON if it is toggled odd number of times 12 | only when `i` has perfect square root, its number of divisors is odd. 13 | 14 | Problem link: https://leetcode.com/problems/bulb-switcher/ 15 | 16 | Time Complexity: O(N) 17 | Space Complexity: O(1) 18 | ''' 19 | 20 | 21 | def bulbSwitcher(n): 22 | bulb = 0 23 | while bulb * bulb <= n: 24 | bulb += 1 25 | return bulb - 1 26 | 27 | 28 | N = int(input()) 29 | print(bulbSwitcher(N)) 30 | 31 | ''' 32 | Input: 5 33 | output: 2 34 | ''' 35 | -------------------------------------------------------------------------------- /Python/cp/house_robber.py: -------------------------------------------------------------------------------- 1 | ''' 2 | The rob function takes an array as input 3 | and returns total amount that can be robbed. 4 | 5 | ''' 6 | 7 | def rob(nums): 8 | """ 9 | :type nums: List[int] 10 | :rtype: int 11 | """ 12 | if nums == [] or len(nums) == 0: 13 | return 0 14 | elif len(nums) == 1: 15 | return nums[0] 16 | 17 | runningTotal = [-1, -1] 18 | runningTotal[0] = nums[0] 19 | runningTotal[1] = max(nums[0], nums[1]) 20 | 21 | for i in range(2, len(nums)): 22 | runningTotal.append(max([nums[i] + runningTotal[i - 2], 23 | runningTotal[i - 1]])) 24 | 25 | return runningTotal[-1] 26 | 27 | def main(): 28 | nums = input() 29 | 30 | rob(nums) 31 | 32 | main() 33 | 34 | # Complexity - 35 | 36 | # Time O(N), 37 | # Space O(N); N = length of array 38 | 39 | # Sample input/output 40 | #input: nums = [2, 7, 9, 3, 1] 41 | #Output: 12 42 | 43 | #input: nums = [1, 2, 3, 1] 44 | #Output: 4 45 | 46 | -------------------------------------------------------------------------------- /Python/cp/staircase_problem.py: -------------------------------------------------------------------------------- 1 | """This program finds the total number of possible combinations that can be used to 2 | climb statirs . EG : for 3 stairs ,combination and output will be 1,1,1 , 1,2 , 2,1 i.e 3 . """ 3 | 4 | def counting_stairs(stair_number): 5 | result = stair_number 6 | # This function uses Recursion. 7 | if(stair_number <=1): 8 | result = 1 9 | else: 10 | result = (counting_stairs(stair_number-1) + counting_stairs(stair_number-2)) 11 | return result 12 | 13 | if __name__ == '__main__': 14 | count_stair = int(input("Enter total number of stairs: ")) 15 | print(f"Total Number of possible Combinations = {counting_stairs(count_stair)}") 16 | 17 | 18 | """Output 19 | Total Number of possible Combinations = 8 20 | Enter total number of stairs: 5 21 | 22 | Time Complexity : O(2^n) 23 | Space Complexity :O(1) 24 | Created by Shubham Patel on 16-12-2020 on WoC 25 | """ 26 | -------------------------------------------------------------------------------- /Python/cp/stock_span.py: -------------------------------------------------------------------------------- 1 | ''' Stock Span Problem 2 | Given a list of prices of a stock for N number of days, 3 | find stock span for each day. 4 | ''' 5 | 6 | 7 | def calcSpan(price): 8 | day = len(price) 9 | stack = [] 10 | span = [0 for i in range(0, day)] 11 | 12 | span[0] = 1 13 | stack.append(0) 14 | 15 | for i in range(1, day): 16 | 17 | while (len(stack) > 0 and price[stack[-1]] <= price[i]): 18 | stack.pop() 19 | 20 | if len(stack) <= 0: 21 | span[i] = i + 1 22 | else: 23 | span[i] = i - stack[-1] 24 | 25 | stack.append(i) 26 | 27 | print(span) 28 | 29 | 30 | prices = list(map(int, input().strip().split())) 31 | calcSpan(prices) 32 | 33 | ''' 34 | sample Input: 35 | 10 30 20 50 20 36 | sample output: 37 | 1 2 1 4 1 38 | 39 | Time complexity: O(n) 40 | space complexity:O(n) 41 | ''' 42 | -------------------------------------------------------------------------------- /Python/graphs/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Python/graphs/dijkstras_algorithm.py: -------------------------------------------------------------------------------- 1 | # Importing Libraries 2 | import matplotlib.pyplot as plt 3 | import networkx as nx 4 | 5 | # Creating an empty Graph 6 | g = nx.Graph() 7 | 8 | # Adding Nodes to empty graph 9 | for i in range(1, 7): 10 | g.add_node(i) 11 | 12 | # Printing Nodes 13 | # print("Nodes are ") 14 | print(g.nodes()) 15 | # Adding Edges 16 | g.add_edge(1, 2) 17 | g.add_edge(1, 3) 18 | g.add_edge(4, 6) 19 | g.add_edge(5, 4) 20 | g.add_edge(2, 3) 21 | g.add_edge(2, 6) 22 | 23 | # Edge Testing 24 | print("Edges are ") 25 | print(g.edges()) 26 | 27 | nx.draw(g) 28 | plt.show() 29 | 30 | # dijkstra's Algorithm 31 | h = nx.Graph() 32 | e = [('a', 'b', 1), ('b', 'c', 2), 33 | ('a', 'c', 3), ('c', 'd', 4), ('d', 'e', 2), ('b', 'e', 1)] 34 | 35 | h.add_weighted_edges_from(e) 36 | nx.draw(h, with_labels=True) 37 | plt.show() 38 | 39 | print(nx.dijkstra_path(h, 'a', 'e')) 40 | -------------------------------------------------------------------------------- /Python/math/Binary_Exponentiation.py: -------------------------------------------------------------------------------- 1 | # Python Program to find Binary Exponent Iteratively and Recursively. 2 | 3 | # Iterative function to calculate exponent. 4 | def binExpo_iterate(a,b): 5 | res=1 6 | while b>0: 7 | if b%2==1: 8 | res=(res*a) 9 | a=a*a 10 | b//=2 11 | return res 12 | 13 | # Recursive function to calculate exponent. 14 | def binExpo_recurse(a,b): 15 | if b==0: 16 | return 1 17 | res=int(binExpo_recurse(a,b//2)) 18 | res=res*res 19 | if b%2==1: 20 | return (res*a) 21 | else: 22 | return res 23 | 24 | # Main function 25 | a=int(input()) 26 | b=int(input()) 27 | 28 | if a==0 and b==0: 29 | print("Math error") 30 | elif b<0: 31 | print("Exponent must be positive") 32 | elif a==0: 33 | print(0) 34 | else: 35 | resIterate=binExpo_iterate(a,b); 36 | resRecurse=binExpo_recurse(a,b); 37 | print(resIterate) 38 | print(resRecurse) 39 | -------------------------------------------------------------------------------- /Python/math/CheckArmstrongNumber.py: -------------------------------------------------------------------------------- 1 | # This program checks whether a number is an armstrong number or not 2 | 3 | import math 4 | 5 | def no_of_digits(n : int) -> int: 6 | count = 0 7 | while n > 0: 8 | count += 1 9 | n = n // 10 10 | return count 11 | 12 | def add(n : int) -> int: 13 | temp = n 14 | tot = 0 15 | nod = no_of_digits(temp) 16 | while n > 0: 17 | r = n % 10 18 | tot += r ** nod 19 | n = n // 10 20 | return tot 21 | 22 | def checkArmstrong(num : int) -> bool: 23 | return add(num) == num 24 | 25 | num = int(input("Enter the number")) 26 | print(add(num)) 27 | if checkArmstrong(num): 28 | print("It is an armstrong number") 29 | else: 30 | print("It is not an armstrong number") 31 | 32 | # Example: 33 | # 1. Input : 153 34 | # Output : It is an armstrong number 35 | # 2. Input : 12 36 | # Output : It is not an armstrong number 37 | -------------------------------------------------------------------------------- /Python/math/Extended_Euclidean_Algorithm.py: -------------------------------------------------------------------------------- 1 | #Extended Euclidean Algorithm 2 | 3 | def Extended_gcd(a, b, x, y): 4 | #Base Case 5 | if a == 0: 6 | x = 0 7 | y = 1 8 | return b 9 | 10 | x1, y1 = 0, 0 11 | gcd = Extended_gcd(b % a, a, x1, y1) 12 | 13 | x = y1 - int(b / a) * x1 14 | y = x1 15 | 16 | return gcd 17 | 18 | #Main code 19 | a = int(input()) 20 | b = int(input()) 21 | x, y = 0, 0 22 | print("GCD of numbers " + str(a) + " and " + str(b) + " is " + str(Extended_gcd(a, b, x, y))) 23 | -------------------------------------------------------------------------------- /Python/math/Fibonacci.py: -------------------------------------------------------------------------------- 1 | """ 2 | Function to print first n Fibonacci Numbers 3 | n takes the input of first n numbers to be printed 4 | """ 5 | 6 | 7 | def fibonaccinumber(n): 8 | """ 9 | >>fibonaccinumber(6) 10 | 0 1 1 2 3 5 11 | 12 | >>fibonaccinumber(10) 13 | 0 1 1 2 3 5 8 13 21 34 55 14 | 15 | """ 16 | a, b = 0, 1 17 | if n < 1: 18 | return 19 | for x in range(0, n-1): 20 | print (b, end=' ') 21 | a, b = b, a + b 22 | 23 | if __name__=="__main__": 24 | n = int(input("Enter the number of terms: ")) 25 | print(0,end=' ') 26 | (fibonaccinumber(n)) 27 | -------------------------------------------------------------------------------- /Python/math/GCD_Euclidean_Algorithm.py: -------------------------------------------------------------------------------- 1 | def calculate_gcd(a, b): 2 | while b: 3 | a, b = b, a % b 4 | return a 5 | 6 | if __name__ == '__main__': 7 | print(calculate_gcd(36, 20)) # Should print 4 8 | print(calculate_gcd(16, 24)) # Should print 8 9 | -------------------------------------------------------------------------------- /Python/math/GCD_of_two_numbers.py: -------------------------------------------------------------------------------- 1 | """ 2 | This is a program written in python for finding GCD of two numbers. 3 | This solution uses recursive approach as implementation. 4 | Recursive approach means a fuction calling itself for which a base condition is given so that the program knows where to terminate. 5 | """ 6 | 7 | #definition of functions to find GCD of 2 numbers. 8 | def gcd_of_nums(x,y): 9 | #choose the smaller number 10 | if x > y: 11 | t=x 12 | x=y 13 | y=t 14 | 15 | if(x==0): 16 | return y 17 | else: 18 | return gcd_of_nums(x,y%x) 19 | 20 | def main(): 21 | num1 = int(input("Enter 1st number: ")) 22 | num2 = int(input("Enter 2nd number: ")) 23 | 24 | print("The GCD is: ", gcd_of_nums(num1,num2)) 25 | 26 | if __name__ == "__main__": 27 | main() 28 | 29 | 30 | """ 31 | Output: 32 | 33 | Enter 1st number: 48 34 | Enter 2nd number: 6 35 | The GCD is: 6 36 | 37 | Enter 1st number: 43 38 | Enter 2nd number: 54 39 | The GCD is: 1 40 | """ 41 | print("\n") 42 | -------------------------------------------------------------------------------- /Python/math/HarshadNumber.py: -------------------------------------------------------------------------------- 1 | """ 2 | A number is said to be a Harshad Number if it is divisible by the sum of its digits. 3 | For example: The number 84 is divisible by the sum (12) of its digits (8, 4). 4 | 5 | """ 6 | 7 | 8 | def isHarshad(number) : 9 | copy = number 10 | 11 | # Calculating the sum of digits of the number 12 | sum_of_digits = 0 13 | while number != 0 : 14 | digit = number % 10 15 | sum_of_digits += digit 16 | number = number // 10 17 | 18 | # Checking if Number is divisible by sum of digits 19 | if copy % sum_of_digits == 0 : 20 | return True 21 | return False 22 | 23 | 24 | user_input = int(input("Enter a number:")) 25 | 26 | if isHarshad(user_input): 27 | print(user_input, "is a Harshad number") 28 | else: 29 | print(user_input, "is not a Harshad number") 30 | 31 | """ 32 | Space Complexity O(1) 33 | Time Complexity O(log(n)) 34 | 35 | Sample input/output: 36 | Enter a number:84 37 | 84 is a Harshad number 38 | 39 | Enter a number:123 40 | 123 is not a Harshad number 41 | 42 | """ 43 | -------------------------------------------------------------------------------- /Python/math/Large_number_factorial.py: -------------------------------------------------------------------------------- 1 | # Python Program to compute Large factorial numbers 2 | 3 | 4 | def factorial_range(start, end): 5 | if start+1 < end: 6 | middle = start + ((end - start)//2) # computing the mid element 7 | # recursive function to half the digits 8 | return factorial_range(start, middle) * factorial_range(middle+1, end) 9 | if start == end: 10 | return start 11 | return start*end 12 | 13 | 14 | def factorialtree(n): # function to divide the factorial in trees 15 | if n < 2: 16 | return 1 17 | return factorial_range(1, n) 18 | 19 | 20 | # Driver Code 21 | n = int(input()) 22 | print(factorialtree(n)) 23 | 24 | ''' 25 | Sample I/O: 26 | input: 27 | 12 28 | Output: 29 | 479001600 30 | Time Complexity: O(logN) 31 | Space Complexity: O(1) 32 | ''' 33 | -------------------------------------------------------------------------------- /Python/math/Least_common_multiple.py: -------------------------------------------------------------------------------- 1 | # Python program to find LCM of two numbers 2 | 3 | # using euclid method to find gcd of two numbers 4 | 5 | 6 | def euclidGCD(number1, number2): 7 | if number2 == 0: 8 | return number1 9 | return euclidGCD(number2, number1 % number2) 10 | 11 | # Calculating lcm of two numbers using GCD 12 | 13 | 14 | def lcm(number1, number2): 15 | return (number1 * number2) // euclidGCD(number1, number2) 16 | 17 | number1, number2 = [int(x) for x in input().split()] 18 | print(lcm(number1, number2)) 19 | 20 | ''' 21 | Sample I/O: 22 | 23 | Sample 1: 24 | Input:761457 614573 25 | Output:467970912861 26 | 27 | Sample 2: 28 | Input:6 8 29 | Output:24 30 | 31 | Time Complexity :O(logn) 32 | Space Complexity:O(1) 33 | ''' 34 | -------------------------------------------------------------------------------- /Python/math/Next_Palindrome.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Python Program to get the next nth palindrome of a given number. 3 | An integer is a palindrome if the reverse of that number is 4 | equal to the original number. 5 | ''' 6 | 7 | 8 | def isPalindrome(num): 9 | return str(num) == str(num)[::-1] 10 | 11 | 12 | def getNthPalindrome(n, start): 13 | if n < 1: 14 | return start 15 | 16 | while not isPalindrome(start + 1): 17 | start += 1 18 | 19 | return getNthPalindrome(n - 1, start + 1) 20 | 21 | 22 | if __name__ == '__main__': 23 | num = int(input('Enter a Number: ')) 24 | n = int(input('Enter nth position: ')) 25 | print(getNthPalindrome(n, num)) 26 | 27 | 28 | ''' 29 | Sample Case: 30 | Example 1: 31 | Enter a number: 12021 32 | Enter nth position: 10 33 | 13031 34 | 35 | Example 2: 36 | Enter a number: 141 37 | Enter nth position: 5 38 | 191 39 | 40 | Time Complexity: O(10^k) 41 | Space Complexity: O(1) 42 | where k = no of digits in given number 43 | ''' 44 | -------------------------------------------------------------------------------- /Python/math/Next_Prime_Number.py: -------------------------------------------------------------------------------- 1 | ''' 2 | INTRODUCTION 3 | 4 | The code below calculates and returns the next prime number from the number given by user. 5 | It takes a number n from user and returns a number x such that 6 | 1. x is greater than n 7 | 2. x is a prime number and 8 | 3. there are no prime numbers between n and x 9 | 10 | ''' 11 | 12 | def next_prime(n): 13 | # looping from next number to find if it prime or not 14 | x = n+1 15 | while True: 16 | flag = False 17 | # checking whether x is divisible by numbers from 2 to it's half 18 | for y in range(2,x//2+1): 19 | if x%y==0: 20 | x+=1 21 | flag = True 22 | break 23 | if flag==False: 24 | return(x) 25 | 26 | n = int(input("Enter a number : ")) 27 | print('Next prime number is ', next_prime(n)) 28 | 29 | ''' 30 | OUTPUT 31 | 32 | Enter a number : 23 33 | Next prime number is 29 34 | 35 | 36 | TIME COMPLEXITY : O(n²) 37 | SPACE COMPLEXITY : O(1) 38 | ''' 39 | -------------------------------------------------------------------------------- /Python/math/Noble_Integer.py: -------------------------------------------------------------------------------- 1 | ''' An integer x is said to be Noble given an array 2 | if the number of integers greater than x are equal to x. 3 | If noble integer is not found output is -1. 4 | ''' 5 | # To find the noble integer from the given list 6 | def nobleint(): 7 | x = 0 8 | lst.sort() 9 | for i in range(0, num - 1): 10 | if lst[i] == lst[i + 1]: 11 | continue 12 | if lst[i] == num - i - 1: 13 | x = 1 14 | return num - i - 1 15 | if x == 0: 16 | return -1 17 | 18 | if __name__ == '__main__': 19 | num = int(input('Enter the number of elements:')) 20 | lst = list(map(int, input('Enter the elements:').split())) 21 | print nobleint(lst, num) 22 | 23 | ''' 24 | Sample Output 25 | 26 | Enter the number of elements:4 27 | Enter the elements:7 3 9 81 28 | 3 29 | Enter the number of elements:3 30 | Enter the elements:2 2 2 31 | -1 32 | 33 | Complexities 34 | Time Complexity:O(nlogn) 35 | Space Complexity:O(1) 36 | ''' 37 | 38 | -------------------------------------------------------------------------------- /Python/math/Palindrome.py: -------------------------------------------------------------------------------- 1 | """ 2 | Python Program to check whether a number is Palindrome or not 3 | An integer is a palindrome if the reverse of that number is equal to the original number. 4 | Example of Palindromes are 11,44,101,121. 5 | 6 | """ 7 | 8 | def palindrome(n): 9 | temp = n 10 | sum = 0 11 | remainder = 0 12 | while n > 0: 13 | remainder = n % 10 14 | sum = sum * 10 + remainder 15 | n = n // 10 16 | if sum == temp: 17 | print (temp, 'is a palindrome') 18 | else: 19 | print (temp, 'is not a palindrome') 20 | if __name__ == '__main__': 21 | n = eval(input('Enter No ')) 22 | palindrome(n) 23 | 24 | """ 25 | Sample Case: 26 | Example 1: 27 | Enter a number: 121 28 | 121 is a palindrome 29 | 30 | Example 2: 31 | Enter a number: 123 32 | 123 is not a palindrome 33 | 34 | Time Complexity: O(n) 35 | Space Complexity: O(1) 36 | 37 | """ 38 | -------------------------------------------------------------------------------- /Python/math/README.md: -------------------------------------------------------------------------------- 1 | 2 | - a 3 | -------------------------------------------------------------------------------- /Python/math/Squares_in_2n_Chessboard.py: -------------------------------------------------------------------------------- 1 | #Find total number of Squares in a N*N cheesboard. 2 | 3 | class Solution: 4 | # using mathematical logic 5 | def squares(self, N): 6 | 7 | sum=0 8 | for i in range(1,N+1): 9 | s=i*i 10 | sum+=s 11 | return sum 12 | 13 | #taking input 14 | num = int(input("Enter the number :")) 15 | obj = Solution() 16 | print("The square : ") 17 | print(obj.squares(num)) 18 | 19 | ''' 20 | Time complexity : O(N) 21 | Space complexity : O(1) 22 | 23 | Input : 24 | Enter the number : 1 25 | Output : 26 | The square is : 1 27 | ''' -------------------------------------------------------------------------------- /Python/math/UglyNumber.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Ugly numbers are numbers whose only prime factors are 2, 3 or 5. 3 | The sequence 1, 2, 3, 4, 5, 6, 8, 9, 10, 12, 15, … 4 | shows the first 11 ugly numbers. 5 | ''' 6 | 7 | 8 | def Divide(a, b): 9 | while a % b == 0: 10 | a = a / b 11 | return a 12 | 13 | 14 | def isUgly(num): 15 | num = Divide(num, 2) 16 | num = Divide(num, 3) 17 | num = Divide(num, 5) 18 | return 1 if num == 1 else 0 19 | 20 | 21 | def getUglyNo(num): 22 | i = 1 23 | count = 1 24 | while num > count: 25 | i += 1 26 | if isUgly(i): 27 | count += 1 28 | return i 29 | 30 | num = int(input("Enter Number: ")) 31 | ugly = getUglyNo(num) 32 | print("Ugly number is ", ugly) 33 | 34 | ''' 35 | Time Complexity:O(n) 36 | Space Complexity: O(1) 37 | 38 | Example 1: 39 | Input: 40 | Enter Number: 10 41 | Output: 42 | Ugly number is 12 43 | 44 | Example 2: 45 | Input: 46 | Enter Number: 4 47 | Output: 48 | Ugly number is 4 49 | ''' 50 | -------------------------------------------------------------------------------- /Python/math/double_factorial.py: -------------------------------------------------------------------------------- 1 | # Double Factorial. 2 | 3 | 4 | def double_fact_i(n): # iterative implementation 5 | ans = 1 6 | for i in range(n, 1, -2): 7 | ans *= i 8 | return ans 9 | 10 | 11 | def double_fact_r(n): # recursive implementation 12 | if n == 0 or n == 1: # checking for 1 or 0 13 | return 1 14 | return n * double_fact_r(n - 2) 15 | 16 | 17 | if __name__ == "__main__": 18 | n = input("enter number") 19 | print("Answer using Iterative method: " + str(double_fact_i(n))) 20 | print("Answer using recursive method: " + str(double_fact_r(n))) 21 | 22 | ''' 23 | output: 24 | enter number4 25 | Answer using Iterative method: 8 26 | Answer using recursive method: 8 27 | enter number5 28 | Answer using Iterative method: 15 29 | Answer using recursive method: 15 30 | Time complexity : O(n) ''' 31 | -------------------------------------------------------------------------------- /Python/math/factorial.py: -------------------------------------------------------------------------------- 1 | # Calculate factorial using iterative approach 2 | def fact(x): 3 | result = 1 4 | for i in range(1,x): 5 | result = result * (i+1) 6 | return result 7 | 8 | # Calculate factorial using recursion 9 | def fact_rec(x): 10 | if x == 0 or x == 1: 11 | return 1 12 | else: 13 | return x * fact_rec(x-1) 14 | 15 | 16 | if __name__ == "__main__": 17 | n = int(input("Enter the number: ")) 18 | print("The factorial of {} is: {} ".format(n, fact(n))) 19 | -------------------------------------------------------------------------------- /Python/math/fibonacci_recursion.py: -------------------------------------------------------------------------------- 1 | # Fibonacci Sequence Using Recursion 2 | 3 | def fibo_rec(x): 4 | """ 5 | >>fibo_rec(6) 6 | 0 1 1 2 3 5 7 | 8 | >>fibo_rec(10) 9 | 0 1 1 2 3 5 8 13 21 34 10 | 11 | """ 12 | if x == 0: 13 | return 0 14 | elif x == 1: 15 | return 1 16 | else: 17 | return fibo_rec(x-1) + fibo_rec(x-2) 18 | 19 | if __name__ == "__main__": 20 | n = int(input("Enter the number of terms: ")) 21 | for i in range(n): 22 | print(fibo_rec(i), end=" ") 23 | -------------------------------------------------------------------------------- /Python/math/min_max_sum.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Given five positive integers, the aim is to find the minimum and maximum values that can be calculated by summing exactly four of the five integers. 3 | 4 | ''' 5 | 6 | def MMSum(a): 7 | # sorting the array so that it becomes easier to find the min and max set of values 8 | a.sort() 9 | minn=0 10 | maxx=0 11 | for i in range(0,4): 12 | # summing up all minimum values 13 | minn+=a[i] 14 | for i in range(1,5): 15 | # summing up all maximum values 16 | maxx+=a[i] 17 | print(minn,maxx) 18 | 19 | # getting the input 20 | user_input = (input().strip().split()) 21 | array = [] 22 | for i in user_input: 23 | array.append(int(i)) 24 | # calling the Min-Max-Sum function 25 | MMSum(array) 26 | 27 | ''' 28 | 29 | COMPLEXITY: 30 | 31 | Time Complexity -> O(N) 32 | Space Complexity -> O(N) 33 | 34 | Sample Input: 35 | 1 2 3 4 5 36 | 37 | Sample Output: 38 | 10 14 39 | 40 | ''' 41 | -------------------------------------------------------------------------------- /Python/math/perfect_square.py: -------------------------------------------------------------------------------- 1 | ''' 2 | A program that returns the count of perfect squares less than or equal to a given number. 3 | It also displays those numbers which are perfect squares within the range of that number. 4 | The number should be greater than or equal to 1 5 | ''' 6 | #importing math function as it will be used for square root 7 | import math 8 | #count function 9 | def countsq(n): 10 | c=0 11 | for i in range(1,n+1): 12 | x=int(math.sqrt(i)) 13 | #Checks whether the number is perfect square or not 14 | if((x*x)==i): 15 | c=c+1 16 | print(i) 17 | return c 18 | #Driver's code 19 | def main(): 20 | n1=int(input("Enter a number")) 21 | c1=countsq(n1) 22 | print("The number of perfect squares are",c1) 23 | if __name__=="__main__": 24 | main() 25 | 26 | 27 | ''' 28 | Time Complexity:O(n) 29 | Space Complexity:O(1) 30 | 31 | Input/Output 32 | Enter a number 55 33 | 1 34 | 4 35 | 9 36 | 16 37 | 25 38 | 36 39 | 49 40 | The number of perfect squares are 7 41 | ''' 42 | -------------------------------------------------------------------------------- /Python/math/positive_decimal_to_binary.py: -------------------------------------------------------------------------------- 1 | #Function to convert a positive decimal number into its binary equivalent 2 | ''' 3 | By using the double dabble method, append the remainder 4 | to the list and divide the number by 2 till it is not 5 | equal to zero 6 | ''' 7 | def DecimalToBinary(num): 8 | #the binary equivalent of 0 is 0000 9 | if num == 0: 10 | print('0000') 11 | return 12 | else: 13 | binary = [] 14 | while num != 0: 15 | rem = num % 2 16 | binary.append(rem) 17 | num = num // 2 18 | #reverse the list and print it 19 | binary.reverse() 20 | for bit in binary: 21 | print(bit, end="") 22 | 23 | #executable code 24 | decimal = int(input("Enter a decimal number to be converted to binary : ")) 25 | print("Binary number : ") 26 | DecimalToBinary(decimal) 27 | 28 | ''' 29 | Sample I/O : 30 | Input : 31 | Enter a decimal number to be converted into binary: 8 32 | 33 | Output: 34 | Binary number: 35 | 1000 36 | 37 | Time Complexity : O(n) 38 | Space Complexity : O(1) 39 | ''' 40 | -------------------------------------------------------------------------------- /Python/math/prime_number_using_sieve_of_Eratosthenes.py: -------------------------------------------------------------------------------- 1 | def sieve_of_Eratosthenes(num): 2 | 3 | not_prime_num = set() 4 | prime_nums = [] 5 | 6 | for i in range(2, num+1): 7 | # checks if the number is in the not_prime_num list 8 | if i in not_prime_num: 9 | continue 10 | 11 | # if number absent in not_prime_num then add that number to prime_num list 12 | # and every multiple of that number to the not_prime_num list 13 | for f in range(i*2, num+1, i): 14 | not_prime_num.add(f) 15 | 16 | prime_nums.append(i) 17 | 18 | # returns a list of prime numbers less then the given number 19 | return prime_nums 20 | 21 | 22 | if __name__ == "__main__": 23 | user_input = int(input("Enter a sequence of comma seprated numbers: ")) 24 | 25 | # calling the sieve_of_Eratosthenes function 26 | prime_numbers = sieve_of_Eratosthenes(user_input) 27 | print(prime_numbers) 28 | -------------------------------------------------------------------------------- /Python/math/reverse_a_number.py: -------------------------------------------------------------------------------- 1 | """ 2 | Python program to reverse a number. 3 | The reverse of a number is a number that is obtained when a number is traversed from right to left. 4 | """ 5 | 6 | # Function to do reverse 7 | 8 | def reverse(n): 9 | # Initializing rev as 0 10 | 11 | rev = 0 12 | while True: 13 | if n == 0: 14 | break 15 | # Adding the last digit 16 | 17 | rev = rev * 10 + n % 10 18 | # Removing the last digit 19 | 20 | n = n // 10 21 | return rev 22 | 23 | if __name__ == '__main__': 24 | # Taking input from user 25 | 26 | n = int(input('Enter the number :')) 27 | # Printing the output 28 | 29 | print ("The reverse of the given number is: {} ".format(reverse(n))) 30 | 31 | """ 32 | Time Complexity - O(n), where 'n' is the number of digits in the number. 33 | Space Complexity - O(1) 34 | 35 | SAMPLE INPUT AND OUTPUT 36 | SAMPLE I 37 | 38 | INPUT 39 | Enter the number: 1234 40 | 41 | OUTPUT 42 | The reverse of the given number is: 4321 43 | 44 | """ 45 | 46 | -------------------------------------------------------------------------------- /Python/math/sum_of_digits.py: -------------------------------------------------------------------------------- 1 | # Python program to Find the Sum of Digits of a Number 2 | 3 | 4 | def sum_of_digits(num): 5 | # Extracting Each digits 6 | # and compute thier sum in 's' 7 | s = 0 8 | while num != 0: 9 | s = s + (num % 10) 10 | num = num // 10 11 | return s 12 | 13 | 14 | if __name__ == '__main__': 15 | # Input the number And 16 | # Call the function 17 | print("Enter the number: ", end="") 18 | n = int(input()) 19 | S = sum_of_digits(abs(n)) 20 | print("The sum of digits of the given number is {}.".format(S)) 21 | 22 | ''' 23 | Time Complexity: O(log(num)), where "num" is the length of the given number 24 | Space Complexity: O(1) 25 | 26 | SAMPLE INPUT AND OUTPUT 27 | 28 | SAMPLE 1 29 | 30 | Enter the number: -12 31 | The sum of digits of the given number is 3. 32 | 33 | SAMPLE 2 34 | 35 | Enter the number: 43258 36 | The sum of digits of the given number is 22. 37 | ''' 38 | -------------------------------------------------------------------------------- /Python/other/CountTriplets.py: -------------------------------------------------------------------------------- 1 | # Count all triplets such that sum of two elements equals the third element. 2 | def find_triplets(arr): 3 | arr.sort() 4 | count = 0 5 | ptr_1 = len(arr) - 1 6 | while ptr_1 >= 2: 7 | ptr_2 = 0 8 | ptr_3 = ptr_1 - 1 9 | while ptr_2 < ptr_3: 10 | if arr[ptr_1] == arr[ptr_2] + arr[ptr_3]: 11 | count += 1 12 | ptr_2 += 1 13 | ptr_3 -= 1 14 | elif arr[ptr_1] > arr[ptr_2] + arr[ptr_3]: 15 | ptr_2 += 1 16 | else: 17 | ptr_3 -= 1 18 | ptr_1 -= 1 19 | return count 20 | 21 | # Driver code 22 | arr = [int(item) for item in input("Enter the list elements : ").split()] 23 | print('Total number of found triplets : {}'.format(find_triplets(arr))) 24 | 25 | ''' 26 | SAMPLE I/O: 27 | 28 | Input: Enter the array elements : 1 4 3 5 7 29 | Output: Total number of found triplets : 3 30 | 31 | Time Complexity : O(n^2) 32 | ''' 33 | -------------------------------------------------------------------------------- /Python/other/Count_Articles.py: -------------------------------------------------------------------------------- 1 | /* Write a Python program to count the number of articles in a given text. */ 2 | 3 | CODE: 4 | 5 | s=input("ENTER TEXT HERE") 6 | y=s.split() 7 | a=0 8 | an=0 9 | the=0 10 | for i in range(len(y)): 11 | if (y[i]=="a" or y[i]=="A"): 12 | a=a+1 13 | if (y[i]=="an" or y[i]=="An"): 14 | an=an+1 15 | if (y[i]=="the" or y[i]=="The"): 16 | the=the+1 17 | print("a:",a) 18 | print("an:",an) 19 | print("the:",the) 20 | print("Total Articles:",a+an+the) 21 | 22 | --------------------------------------------------------------------------------------------- 23 | TIME COMPLEXITY: O(N) (Where N is length) 24 | SPACE COMPLEXITY: O(N) 25 | ------------------------------------------------------------------------------------------ 26 | OUTPUT: 27 | 28 | ENTER TEXT HERE A was the an I am a the she was this that the an a the 29 | a: 3 30 | an: 2 31 | the: 4 32 | Total Articles: 9 33 | -------------------------------------------------------------------------------- /Python/other/HappyNumber.py: -------------------------------------------------------------------------------- 1 | def numSquareSum(num): 2 | squareSum = 0; 3 | while(num): 4 | squareSum += (num % 10) * (num % 10); 5 | num = int(num / 10); 6 | return squareSum; 7 | 8 | def isHappynumber(num): 9 | 10 | slow = num 11 | fast = num 12 | while(True): 13 | 14 | slow = numSquareSum(slow) 15 | fast = numSquareSum(numSquareSum(fast)); 16 | if(slow != fast): 17 | continue 18 | else: 19 | break 20 | return (slow == 1) 21 | 22 | # Driver Code 23 | num = int(input("Enter a number: ")) 24 | if (isHappynumber(num)): 25 | print(num , "is a Happy number") 26 | else: 27 | print(num , "is not a Happy number") 28 | 29 | """ 30 | Time Complexity: O(logN) 31 | Space Complexity: O(logN) 32 | 33 | Sample Input: 34 | Enter a number: 13 35 | Sample Output: 36 | 13 is a Happy number 37 | """ 38 | -------------------------------------------------------------------------------- /Python/other/Kadanes_Algorithm.py: -------------------------------------------------------------------------------- 1 | # To find the contiguous sub-array with the largest sum in 2 | # a one-dimensional array of numbers 3 | 4 | 5 | def kadane(nums): 6 | 7 | current_max = global_max = nums[0] 8 | 9 | for i in range(1, len(nums)): 10 | 11 | current_max = max(nums[i], nums[i] + current_max) 12 | 13 | if current_max > global_max: 14 | global_max = current_max 15 | return global_max 16 | 17 | if __name__ == '__main__': 18 | print(kadane([-2, -3, -1, -5])) # Output: -1 19 | print(kadane([-2, 1, -3, 4, -1, 2, 1, -5, 4])) # Output: 6 20 | -------------------------------------------------------------------------------- /Python/other/Program_to_rotation_array.py: -------------------------------------------------------------------------------- 1 | def array_rotation(): 2 | save = [] 3 | rest_arr = [] 4 | for i in arr: 5 | if i == Start_element or i < Start_element: 6 | save.append(i) 7 | else: 8 | rest_arr.append(i) 9 | 10 | rest_arr.extend(save) 11 | print('rest arry =', rest_arr) 12 | 13 | arr = list(input("Enter the no. elements:\n").split()) 14 | Start_element = input("Stating from which element:\n") 15 | ending_element = input("Enter the ending element:\n") 16 | array_rotation() 17 | 18 | ''' 19 | >>Time & Space Complexity is O(n) 20 | 21 | INPUT 22 | 23 | >>Enter the no. elements: 24 | 1 2 3 4 5 6 7 25 | >>Stating from which element: 26 | 2 27 | >>Enter the ending element: 28 | 7 29 | 30 | OUTPUT 31 | >>rest arry = ['3', '4', '5', '6', '7', '1', '2'] 32 | 33 | 34 | ''' -------------------------------------------------------------------------------- /Python/other/Reverse_string_using_stack.py: -------------------------------------------------------------------------------- 1 | #class of stack 2 | class stack: 3 | def __init__(self): 4 | self.items=[] 5 | def push(self,item): 6 | self.items.append(item) 7 | def pop(self): 8 | return self.items.pop() 9 | def is_empty(self): 10 | return self.items==[] 11 | 12 | 13 | #function to reverse a function 14 | def reverse(string): 15 | 16 | """ 17 | >>Input:ziuQ 18 | >>Output:Quiz 19 | 20 | """ 21 | x=len(string) 22 | l=0 23 | while l> 4) 8 | 9 | number = int(input("Enter Number: ")) 10 | print("After swapping the nibbles:") 11 | print(swapNibbles(number)) 12 | 13 | ''' 14 | Sample I/O: 15 | Input 16 | Enter Number: 100 17 | 18 | Output: 19 | After swapping the nibbles: 20 | 70 21 | 22 | Time Complexity: O(1) 23 | Space Complexity: O(1) 24 | 25 | ''' 26 | -------------------------------------------------------------------------------- /Python/other/Unique_number_III.py: -------------------------------------------------------------------------------- 1 | # Unique_Number_III 2 | # Given an array that contains all elements occurring 3 times, but one 3 | # occurs only once. Find that unique element. 4 | 5 | 6 | def unique_element(array, size): 7 | for i in range(size): 8 | j = 0 9 | while(j < size): 10 | if (i != j and array[i] == array[j]): 11 | break 12 | j += 1 13 | if (j == size): 14 | return array[i] 15 | 16 | return -1 17 | 18 | 19 | print("Enter Elements:") 20 | array = input().split() 21 | size = len(array) 22 | print("Unique element:") 23 | print(unique_element(array, size)) 24 | 25 | ''' 26 | Sample I/O: 27 | Input: 28 | Enter Elements: 29 | 1 1 1 4 2 2 2 3 3 3 30 | 31 | Output: 32 | Unique element: 33 | 4 34 | 35 | Time Complexity: O(size*size) 36 | Space Complexity:O(1) 37 | ''' 38 | -------------------------------------------------------------------------------- /Python/other/Wave_Array.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sorting the array into a wave-like array. 3 | For eg: arr[] = {1,2,3,4,5} 4 | Output: 2 1 4 3 5 5 | """ 6 | 7 | 8 | def convertToWave(length,array): 9 | for i in range(0, length - length%2, 2): #swapping alternatively 10 | temp=array[i] 11 | array[i]=array[i+1] 12 | array[i+1]=temp 13 | return array 14 | 15 | arr = list(map(int,input("Enter the elements of the array : ").split())) 16 | N = len(arr) # length of the array 17 | 18 | arr = convertToWave(N,arr) 19 | 20 | print("Wave Array: ") 21 | for el in arr: 22 | print(el, end=" ") 23 | 24 | 25 | """ 26 | Time complexity : O(1) 27 | Space complexity : O(1) 28 | 29 | INPUT:- 30 | Enter the elements of the array : 1 2 3 4 5 6 7 31 | OUTPUT:- 32 | Wave Array: 2 1 4 3 6 5 7 33 | 34 | """ 35 | -------------------------------------------------------------------------------- /Python/other/find_the_numbers.py: -------------------------------------------------------------------------------- 1 | # Python program to find the unique numbers in an array out 2 | # of which two numbers occur exactly once and are distinct. 3 | # You need to find the other two numbers and print them in ascending order. 4 | 5 | if __name__ == '__main__': 6 | n = int(input("Enter the number of elements: ")) 7 | arr = list(map(int, input().split(' ')[:n])) 8 | xors = 0 9 | for i in range(0, n): 10 | xors = xors ^ arr[i] 11 | xors = xors & ~(xors - 1) 12 | x = 0 13 | y = 0 14 | for i in range(0, n): 15 | if arr[i] & xors > 0: 16 | x = x ^ arr[i] 17 | else: 18 | y = y ^ arr[i] 19 | if x > y: 20 | swap(x, y) 21 | print("The distinct numbers are ", x, " and ", y) 22 | 23 | # Time Complexity: O(N) 24 | # Space Complexity: O(1) 25 | 26 | # Input 27 | # Enter the number of elements: 6 28 | # 2 3 1 4 2 1 29 | 30 | # Ouput 31 | # The distinct numbers are 3 and 4 32 | -------------------------------------------------------------------------------- /Python/other/remove_outermost_parenthesis.py: -------------------------------------------------------------------------------- 1 | def removeOuterParentheses(S): 2 | res, opened = [], 0 3 | for c in S: 4 | if c == '(' and opened > 0: 5 | res.append(c) 6 | if c == ')' and opened > 1: 7 | res.append(c) 8 | opened += 1 if c == '(' else -1 9 | return "".join(res) 10 | 11 | str = input("Enter string: ") 12 | result = removeOuterParentheses(str) 13 | print(result) 14 | 15 | 16 | """ 17 | Time complexity: O(n) 18 | Space complexity: O(n) 19 | Sample Input 1: 20 | Enter string: (()())(()) 21 | Output: ()()() 22 | 23 | Sample Input 2: 24 | Enter string: ()() 25 | Output: "" 26 | 27 | """ 28 | -------------------------------------------------------------------------------- /Python/other/stringkth.py: -------------------------------------------------------------------------------- 1 | ''' 2 | A program to remove the kth index from a string and print the remaining string.In case the value of k 3 | is greater than length of string then return the complete string as it is. 4 | ''' 5 | #main function 6 | def main(): 7 | s=input("enter a string") 8 | k=int(input("enter the index")) 9 | l=len(s) 10 | #Check whether the value of k is greater than length 11 | if(k>l): 12 | print(s) 13 | #If k is less than length of string then remove the kth index value 14 | else: 15 | s1='' 16 | for i in range(0,l): 17 | if(i!=k): 18 | s1=s1+s[i] 19 | print(s1) 20 | if __name__== "__main__": 21 | main() 22 | 23 | ''' 24 | Time Complexity:O(n),n is length of string 25 | Space Complexity:O(1) 26 | 27 | Input/Output: 28 | enter a string python 29 | enter the index 2 30 | pyhon 31 | ''' 32 | -------------------------------------------------------------------------------- /Python/search/Linear_Search.py: -------------------------------------------------------------------------------- 1 | def linearSearch(arr, x): 2 | pos = -1 3 | for i in range(len(arr)): 4 | if arr[i] == x: 5 | pos = i 6 | print("Found at {}".format(pos)) 7 | 8 | if pos == -1: 9 | print("Not Found") -------------------------------------------------------------------------------- /Python/search/bilinear.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Bilinear search is searching algorithm where it is search for a element 3 | from the both end. It is a improved version of linear search. 4 | ''' 5 | 6 | 7 | def bilinear(x, arr): 8 | siz = len(arr) 9 | p = 0 10 | i = 0 11 | j = siz-1 12 | 13 | while i < j: 14 | if arr[i] != x and arr[j] != x: 15 | i += 1 16 | j -= 1 17 | else: 18 | p = 1 19 | break 20 | if p == 1: 21 | return True 22 | else: 23 | return False 24 | 25 | if __name__ == "__main__": 26 | print('enter the list:') 27 | l = list(map(int, input().split(' '))) 28 | 29 | ele = int(input("enter the element to check:")) 30 | 31 | if bilinear(ele, l): 32 | print('element found') 33 | elif bilinear(ele, l) is False: 34 | print("element not found") 35 | -------------------------------------------------------------------------------- /Python/sort/Bead_Sort.py: -------------------------------------------------------------------------------- 1 | #Bead sort (a.k.a Abacus sort, or Gravity sort) is a sorting algorithm 2 | # that can sort a list of positive integers . 3 | # We can sort negative numbers too by adding a constant to all the integers and subracting it later 4 | #Bead sort is a natural algorithm 5 | #It uses (imitates) gravity to sort an input list 6 | 7 | def bead_sort(a): 8 | minimum, maximum = min(a), max(a) 9 | n = len(a) 10 | 11 | # Initialize a temporary array filled with minimum 12 | temp = [minimum] * n 13 | for i in range(maximum-1, minimum-1, -1): 14 | k = 0 15 | for j in range(n): 16 | if a[j] > i: 17 | temp[k] += 1 18 | k += 1 19 | 20 | # Copy temp array back into original array 21 | # replacing the array into sorted order 22 | # temp array is reverse sorted, so copy backwards for ascending order 23 | for i in range(n): 24 | a[i] = temp[n-i-1] 25 | 26 | return a 27 | 28 | if __name__ == "__main__": 29 | a=[] 30 | print(bead_sort(a)) -------------------------------------------------------------------------------- /Q-Sharp/blockchain/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/cp/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/cryptography/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/Q-Sharp/cryptography/README.md -------------------------------------------------------------------------------- /Q-Sharp/dp/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/ds/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/graphs/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/math/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/other/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/search/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Q-Sharp/sort/README.md: -------------------------------------------------------------------------------- 1 | a 2 | -------------------------------------------------------------------------------- /Resources/README.md: -------------------------------------------------------------------------------- 1 | # Resources 2 | 3 | Everything you need to know to ace Data Structures and Algorithms 🙌 4 | -------------------------------------------------------------------------------- /Resources/Radix_Sort.md: -------------------------------------------------------------------------------- 1 | # RADIX SORT 2 | 3 | It is a non-comparative sorting algorithm. It is used for sorting the array which contains numbers in the range of 1 to $n^2$. It performs digit by digit sort starting from least significant digit to most significant digit. 4 | 5 | The steps and execution of radix sort are explained briefly with the help of an example. 6 | 7 | ## ANALYSIS 8 | 9 | Input Data: 170, 45, 75, 90, 802, 24, 2, 66 10 | We start sorting from the least significant digit. 11 | 12 | ##### Sorting by one’s place 13 | 14 | [{170, 90}, {02, 802, 02}, {45, 75}, {66} 15 | 16 | ##### Sorting by ten's place 17 | 18 | [{02, 802, 02}, {45}, {66}, {170, 75}, {90}] 19 | 20 | ##### Sorting by hundreds place 21 | 22 | [{002, 002, 045, 066, 075, 090}, {170}, {802}] 23 | 24 | ## Time & Space Complexity of the Algorithm 25 | 26 | #### Worst Case Time Complexity [ Big-O]: O(w.n) where w is the no of bits required to store each value. 27 | 28 | #### Worst Case Space Complexity : O(w+n) 29 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | Since this repo mainly deals with DS and Algos, if you've encountered a security issue, 4 | you should probably wear a tinfoil hat :) 5 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-architect 2 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/TesseractCoding/NeoAlgo 2 | 3 | go 1.16 4 | -------------------------------------------------------------------------------- /img/fork.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/fork.png -------------------------------------------------------------------------------- /img/git add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git add.png -------------------------------------------------------------------------------- /img/git branch.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git branch.png -------------------------------------------------------------------------------- /img/git checkout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git checkout.png -------------------------------------------------------------------------------- /img/git clone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git clone.png -------------------------------------------------------------------------------- /img/git commit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git commit.png -------------------------------------------------------------------------------- /img/git push.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/git push.png -------------------------------------------------------------------------------- /img/grover.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/grover.png -------------------------------------------------------------------------------- /img/issue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/issue.png -------------------------------------------------------------------------------- /img/issue_template_get_started_button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/issue_template_get_started_button.png -------------------------------------------------------------------------------- /img/neo_algo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/neo_algo.png -------------------------------------------------------------------------------- /img/new_issue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/new_issue.png -------------------------------------------------------------------------------- /img/pull_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/pull_2.png -------------------------------------------------------------------------------- /img/pull_request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HarshCasper/NeoAlgo/4f1e5bdd6d9d899fa354de94740e0aecf5ecd2be/img/pull_request.png --------------------------------------------------------------------------------