├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── feature_request.md │ └── script-addition.md ├── PULL_REQUEST_TEMPLATE.md ├── auto_assign.yml ├── labels.json ├── weekly-digest.yml └── workflows │ └── issue-label.yml ├── Algorithms ├── Backtracking │ ├── C++ │ │ ├── Rat in a Maze.cpp │ │ ├── Sudoku Backtracking-7.cpp │ │ ├── n-queen.cpp │ │ └── print all permutations of a given string.cpp │ ├── Java │ │ ├── NQueenBacktracking.java │ │ ├── NQueens.java │ │ ├── RatInMazeRecursion.java │ │ ├── SudokuBacktracking.java │ │ └── nQueensPermutationCombination.java │ ├── Print_all_permutations_of_a_String.java │ └── Python │ │ └── ratInMaze.py ├── Bucket_Sort_JAVA.java ├── Disjoint Set │ └── C++ │ │ └── union_find_algorithm.cpp ├── Divide and Conquer │ └── C++ │ │ └── Closest Pair of Points using Divide and Conquer algorithm.cpp ├── Dynamic Problems │ ├── B Frog2.cpp │ ├── C++ │ │ ├── A Frog1.cpp │ │ ├── Alive.cpp │ │ ├── Buy and Sell stock atmost k transactions.cpp │ │ ├── Edit Distance.cpp │ │ ├── Equal_sum_Partition.cpp │ │ ├── Fibonacci numbers.cpp │ │ ├── FloydWarshall.cpp │ │ ├── Friends Pairing .cpp │ │ ├── Gold Mine Problem.cpp │ │ ├── Largest Sum.cpp │ │ ├── Longes_common_sbsequnce.cpp │ │ ├── Longestsubarray.cpp │ │ ├── Painting the Fence.cpp │ │ ├── Rod Cutting.cpp │ │ ├── Tiling Problem.cpp │ │ ├── Tower_Of_Hanoi (2).cpp │ │ └── Ugly Number.cpp │ ├── C │ │ └── bellmanford.c │ ├── Java │ │ ├── Equal_sum_Partition.java │ │ ├── FloydWarshall.java │ │ ├── Product_of_Self_Array.java │ │ ├── longest_increasing_subsequence.java │ │ └── nth Catalan Number.java │ ├── Python │ │ ├── BooleanParenthesization.py │ │ ├── FlodyWarshall.py │ │ ├── FloydWarshall.py │ │ ├── LexicographicallySmallestPermutation.py │ │ ├── Print Fibonacci sequence using 2 variables.py │ │ └── RegularExpressionMatchingAlgorithm.py │ ├── TowerOfHanoi.java │ ├── countsequencewith_product.java │ └── k_arrayheap.cpp ├── Graph │ ├── C++ │ │ ├── Bellman.cpp │ │ ├── BellmanFord.cpp │ │ ├── DFSGraphValidation.cpp │ │ ├── Kahn's Algo.cpp │ │ ├── Kahn’s Algorithm for Topological Sort.cpp │ │ ├── Krushal's Algo.cpp │ │ ├── TopologicalSort.cpp │ │ └── dfs_entry_exit_time.cpp │ ├── C │ │ ├── Kahn'sAlgo.c │ │ ├── connected_components.c │ │ └── graph_col.c │ └── Python │ │ ├── Graph Coloring.py │ │ └── GraphColouringProblem.py ├── Graphs │ └── Prisoners_escape.cpp ├── Greedy Algorithms │ ├── 0-1 KNAPSACK PROBLEM.c │ ├── C++ │ │ ├── Dijkstra’s shortest path algorithm.cpp │ │ ├── Fractional_Knapsack_in_C++.cpp │ │ ├── Greedy_algorithm_to_find_minimum_number_of_coins.cpp │ │ ├── Job Sequencing Problem.cpp │ │ └── Maximum sum removing k numbers.cpp │ ├── C │ │ └── dijsktra_algo.c │ ├── Java │ │ ├── Activity Selection Problem.java │ │ ├── Fractional Knapsack Problem.java │ │ ├── K Centers Problem.java │ │ └── Kruskal’s Minimum Spanning Tree Algorithm.java │ ├── Job Sequencing Problem.py │ ├── Police and Thieve.cpp │ └── Taylor_series.cpp ├── Hashing Techniques │ └── Chaining.cpp ├── JohnsonAlgorithm.cpp ├── Kahn’s Algorithm for Topological Sort.cpp ├── LinkedList │ ├── circularll.java │ ├── doublyll.java │ ├── linkedlist.java │ └── singlyll.java ├── Longest_Consecutive_Sequence.py ├── MCM_Memoisation.cpp ├── Miscellaneous │ ├── C++ │ │ ├── Brian_Kernighan's_Algorithm.cpp │ │ ├── Chinese_Remainder_Theorem.cpp │ │ ├── Dutch National Flag Algorithm.cpp.cpp │ │ ├── K_Closest_Points_to_Origin.cpp │ │ ├── Klee's Algorithm.cpp │ │ ├── Longest Consecutive Sequence.cpp │ │ ├── Longest Substring without repeating characters.cpp │ │ ├── Palindromic_Partitions.cpp │ │ ├── PrimeFactorization.cpp │ │ ├── Rabin Karp algorithm.cpp │ │ ├── RatInMaze.cpp │ │ ├── Recursive Modular Exponentiation.cpp │ │ ├── Russian_Peasant_Algorithm.cpp │ │ ├── Sieve of Eratosthenes.cpp │ │ ├── Sieve_of_Eratosthenes.cpp │ │ ├── call_by_reference.cpp │ │ ├── call_by_value.cpp │ │ ├── contamenatedwords.cpp │ │ ├── hailstone_sequence.cpp │ │ ├── longest increasing subsequence.cpp │ │ ├── perfect_no.cpp │ │ ├── string_tokenizer.cpp │ │ └── tower_of_hanoi.cpp │ ├── C │ │ ├── A Very Big Sum.c │ │ ├── Sieve of Eratosthenes.c │ │ ├── Simple Array Sum.c │ │ ├── Solve Me First.c │ │ ├── pascaltriangle.c │ │ ├── stockspanprob.c │ │ └── towerOFHanoi.c │ ├── Java │ │ ├── Adjacent Difference Algo │ │ ├── AdjacentDifference.java │ │ ├── Daimond.java │ │ ├── Rabin-Karp Algo.java │ │ ├── SandGlass.java │ │ ├── SeiveOfEratosthenes.java │ │ └── WarnsdorffAlgorithm.java │ └── Python │ │ ├── Coin Change.py │ │ ├── Concatenation.py │ │ ├── N-th Tribonacci Number.py │ │ ├── Palindromic_Partition.py │ │ ├── Russian peasant multiplication.py │ │ ├── Setbitposition.py │ │ ├── Sieve_of_Eratosthenes.py │ │ ├── TowerOfHanoi.py │ │ ├── partition_problem.py │ │ └── power_of_2_(Bit_Manipulation).py ├── Searching and Sorting │ ├── C++ │ │ ├── BST Sort.cpp │ │ ├── Bead_Sort.cpp │ │ ├── Binary Insertion Sort.cpp │ │ ├── BinarySearch_Comparisons_Count.cpp │ │ ├── Binary_Insertion_Sort.cpp │ │ ├── BubbleSort.exe │ │ ├── BubbleSort_Comparisons_Count.cpp │ │ ├── Count Sort.cpp │ │ ├── DNF.cpp │ │ ├── Heap Sort.cpp │ │ ├── Insertion Sort using Call By Reference method.cpp │ │ ├── Insertion Sort.cpp │ │ ├── InsertionSort_Comparisons_Count.cpp │ │ ├── Interpolation.cpp │ │ ├── Jump_search.cpp │ │ ├── KmpAlgorithm.cpp │ │ ├── Merge Sort.cpp │ │ ├── Quick Sort.cpp │ │ ├── Radix_Sort.cpp │ │ ├── Selection Sort.cpp │ │ ├── SelectionSort_Comparisons_Count.cpp │ │ ├── Shell Sort.cpp │ │ ├── Shell_Sort.cpp │ │ ├── Sparse_search.cpp │ │ ├── Ternary_search.cpp │ │ ├── Topological_sort.cpp │ │ ├── Ubiquittous_Binary_Search.cpp │ │ ├── Wave sort.cpp │ │ ├── binary_recursive_search.cpp │ │ ├── bucket_sort.cpp │ │ ├── circle_sort.cpp │ │ ├── comb_sort.cpp │ │ ├── heapSort.cpp │ │ ├── interpolationSearch.cpp │ │ ├── linear-search.cpp │ │ └── sorting.cpp │ ├── C │ │ ├── Binary_search.c │ │ ├── Bubble Sort.c │ │ ├── Insertion Sort using Call By Reference method.c │ │ ├── InterpolationSearch.c │ │ └── sort_012_arr.c │ ├── Java │ │ ├── ArrayIns.class │ │ ├── ArrayInsertsort.class │ │ ├── ArrayInsertsort.java │ │ ├── Jump Search.java │ │ └── RadixSort.java │ ├── Python │ │ ├── Bubble Sort in Python.py │ │ ├── Bubble_sort._python.py │ │ ├── Bucket_Sort.py │ │ ├── KMP_Algorithm.py │ │ └── Shell_sort.py │ ├── searching_bst.cpp │ └── sort012.java ├── rabin_karp_algorithm.py ├── rotate90.cpp └── superdigit.c ├── Atcoder dp ├── N - Slimes.cpp └── X - Tower.cpp ├── CODE_OF_CONDUCT.md ├── Codechef ├── C++ │ ├── AND Plus OR(ANDOR).cpp │ ├── ATM (HS08TEST).cpp │ ├── Add two number(FLOW001).cpp │ ├── An Interesting Sequence (ISS).cpp │ ├── Arrange the Students (ARRSTUD).cpp │ ├── Arrangement of Balls (ARRBALLS).cpp │ ├── Beautiful Pairs (BUTYPAIR).cpp │ ├── Bella_ciao.cpp │ ├── Binary String MEX (MEXSTR).cpp │ ├── Birthday_gift.cpp │ ├── Bitwise tuples(BITTUP).cpp │ ├── BitwiseTuples.cpp │ ├── Body Mass Index (BMI).cpp │ ├── Boolean Game (BOOLGAME).cpp │ ├── BugCrush 2 Question 1 (BUGC201).cpp │ ├── BugCrush 2 Question 2 (BUGC202).cpp │ ├── BugCrush 2 Question 3 (BUGC203).cpp │ ├── BugCrush 2 Question 4 (BUGC204).cpp │ ├── BugCrush 2 Question 6 (BUGC206).cpp │ ├── BugCrush 2 Question 7 (BUGC207).cpp │ ├── Bytelandian gold coins.cpp │ ├── CARVANS.cpp │ ├── Ceiling Sum (CEILSUM).cpp │ ├── Charges.cpp │ ├── Chef In Infinite Plane (CHFPLN).cpp │ ├── Chef and Coupon (COUPON2).cpp │ ├── Chef and Dice (SDICE).cpp │ ├── Chef and Groups (GROUPS).cpp │ ├── Chef and Machine (CMACHINE).cpp │ ├── Chef and Spells (CHFSPL).cpp │ ├── Chess Format (CHSFORMT).cpp │ ├── Chess Match (BLITZ3_2).cpp │ ├── Coin Flip (CONFLIP).cpp │ ├── Coldplay (SLOOP).cpp │ ├── College Life 4 (COLGLF4).cpp │ ├── Consecutive Adding (CONSADD).cpp │ ├── Cricket Ranking (CRICRANK).cpp │ ├── Dense Graph (DENSEGRP).cpp │ ├── Destroy the EMP (CHAOSEMP).cpp │ ├── Divisibility Test (DIVTEST).cpp │ ├── Equinox Strings (EQUINOX).cpp │ ├── Expedition(Expedi).cpp │ ├── FInd Square Root(FSQRT).cpp │ ├── Find Remainder(FLOW002).cpp │ ├── FixedNumberOfFixedPoints.c++ │ ├── Food Chain (FODCHAIN).cpp │ ├── Fuel Mountains (MFUEL).cpp │ ├── Gasoline Introduction (BEGGASOL).cpp │ ├── Geometric Possibility (GEOPOS).cpp │ ├── Golf (LKDNGOLF).cpp │ ├── Hail_XOR.cpp │ ├── Hoop_jump.cpp │ ├── ICPC Balloons (BALLOON).cpp │ ├── Interesting XOR (IRSTXOR).cpp │ ├── Interesting XOR.cpp │ ├── Kid & Table (TABLE).cpp │ ├── LCS-3.cpp │ ├── LKDNGOLF.cpp │ ├── Lapindromes (LAPIN).cpp │ ├── Lazy Ravi (RJ3).cpp │ ├── MINNOTES.cpp │ ├── Maximum Production (EITA).cpp │ ├── Minimum Dual Area.cpp │ ├── Modular Equations (MODEQ).cpp │ ├── Multiple of 3 (MULTHREE).cpp │ ├── No Time To Wait (NOTIME).cpp │ ├── Noble Prize (NOBEL).cpp │ ├── Oliver.cpp │ ├── Paparazzi Gennady (PAPARAZI).cpp │ ├── Pawri Meme (PAWRI).cpp │ ├── Possible Victory (T20MCH).cpp │ ├── Potter and his Magic Wand (CC022).cpp │ ├── Prime Game.cpp │ ├── Principal & Position (PR_PO).cpp │ ├── Rating Game (SSEC0014).cpp │ ├── Red Alert (REDALERT).cpp │ ├── Relativity (RELATIVE).cpp │ ├── Reverse the Number(FLOW007).cpp │ ├── SUMMER-HEAT.cpp │ ├── Shoe Fit (SHOEFIT).cpp │ ├── Shortest_Route.cpp │ ├── Sleep Cycle (SLPCYCLE).cpp │ ├── Smallest Positive Whole Number(SMOL).cpp │ ├── Smart Phone (ZCO14003).cpp │ ├── Solubility (SOLBLTY).cpp │ ├── Space Arrays (SPACEARR).cpp │ ├── Split the String (SPLITIT).cpp │ ├── String Permutation (STRPER).cpp │ ├── Strong Language (SSCRIPT).cpp │ ├── Sum of Digits(FLOW006).cpp │ ├── The Wave (WAV2).cpp │ ├── Three Dices (THREDICE).cpp │ ├── Tic Tac Toe (TCTCTOE).cpp │ ├── Total Correct Submissions (TOTCRT).cpp │ ├── Total_Correct_Submissions.cpp │ ├── Total_Expenses.cpp │ ├── Tree House (THOUSES).cpp │ ├── Tree Permutations (TREEPERM).cpp │ ├── Valid Pair (SOCKS1).cpp │ ├── Valid Paths (VPATH).cpp │ ├── Watermelon (WATMELON).cpp │ ├── Weight Balance (WEIGHTBL).cpp │ ├── Wireless Electricity Challenge (WIREL).cpp │ ├── World Record (BOLT).cpp │ ├── Worthy Matrix (KAVGMAT).cpp │ ├── XOR Equality (XOREQUAL).cpp │ ├── XOR Folding (XOREQUAL).cpp │ ├── XOR-ORED (XORORED).cpp │ ├── XxOoRr (XXOORR).cpp │ ├── Zoo Game (ZOOGAME).cpp │ ├── codechef_chfheist.cpp │ ├── codechef_visa.cpp │ ├── coin_triangle_problem.cpp │ ├── false_number.cpp │ ├── falseno.cpp │ ├── gcd.cpp │ ├── htmltags.cpp │ ├── infiniteplane.cpp │ ├── mod-equality.cpp │ ├── pattern23 .cpp │ ├── queries.cpp │ ├── richirich.cpp │ └── unpleasant_ones.cpp ├── C │ ├── Discrepancies_in_the_Voters_List VOTERS.c │ ├── Strong_Language SSCRIPT.c │ ├── Turbo Sort.c │ ├── cheflandvisa.c │ └── dividingStamps.c ├── FlappyBird.java ├── Java │ ├── Bella_ciao.java │ ├── BirthdayGift.java │ ├── Bitwise Tuples(BITTUP).java │ ├── Chess Format.java │ ├── Chess_Match.java │ ├── CoinsAndTriangle.java │ ├── CovidAnalyzer.java │ ├── Food Chain.java │ ├── From Rational to Binary.java │ ├── HTML_Tags.java │ ├── RedAlert.java │ ├── Relativity.java │ ├── SpaceArrays.java │ ├── TheWave.java │ ├── The_Lead_Game.java │ ├── Total Correct Submissions.java │ ├── Total Expenses.java │ ├── Turbo Sort.java │ ├── Unpleasant Ones.java │ ├── atm.java │ ├── cheflandvisa.java │ ├── chefqueries.java │ ├── racingHorses.java │ ├── studyingAlphabet.java │ ├── summer_heat.java │ ├── xor.java │ └── xor_folding.java └── Python │ ├── Bella_ciao.py │ ├── Chef and Groups.py │ ├── Chefland Visa (VISA).py │ ├── Coins And Triangle (TRICOIN).py │ ├── CyclicQuad.py │ ├── Factorial.py │ ├── ICPC_BALLOON.py │ ├── Lapindromes.py │ ├── No Time To Wait.py │ ├── Nobel.py │ ├── Possible Victory.py │ ├── Small Factorials.py │ ├── Team Name.py │ ├── Tsort.py │ ├── gold_coin.py │ ├── hollow butterfly pattern.py │ ├── pattern_codechef.py │ └── smartphone.py ├── Codeforces ├── 1328_A_Divisibility_Problem.cpp ├── 1547_C_Pair_Programming.cpp ├── C++ │ ├── 1-based index of lucky number.cpp │ ├── 1343B_Balanced_Array.cpp │ ├── 1364_A_XXXXX.cpp │ ├── 1367B_Even_Array.cpp │ ├── 1542A_Odd_Set.cpp │ ├── 1547_B_Alphabetical_String.cpp │ ├── 570_B_Simple_Game.cpp │ ├── 977_C_Less_or_Equal.cpp │ ├── A_AquaMoon and Two Arrays.cpp │ ├── A__DieRoll.cpp │ ├── B_Borze.cpp │ ├── B_Drinks.cpp │ ├── Balanced_Rating_Changes._codeforces.cpp │ ├── D. Same Differences.cpp │ ├── DeletingDivisors.cpp │ ├── Dima-Sereja_problem.cpp │ ├── Fair Playoff.cpp │ ├── Friends_and_Candies_Codeforces.cpp │ ├── I_Hate_1111(Problem1526B).cpp │ ├── Indian Coin Change.cpp │ ├── Kuriyama_Mirai's_Stones.pp.cpp │ ├── Marvolo_Gaunt's_Ring.cpp │ ├── Mountain_Scenery.cpp │ ├── PAIR OF TOPICS.CPP │ ├── Phoenix and Puzzle.cpp │ ├── Pythagorean_Triples(Problem_1487D).cpp │ ├── Q1_Lucky_sum_of_digits.cpp │ ├── Q2_Letters.cpp │ ├── Rank_List.cpp │ ├── Shower_Line.cpp │ ├── Unlucky_Ticket.cpp │ ├── codeforces_ beautiful matrix.cpp │ ├── dice_tower.cpp │ ├── evenodd.cpp │ ├── new_password_codeforces.cpp │ ├── twins.cpp │ ├── watermelon.cpp │ └── way_to_long_word.cpp ├── C │ ├── DeletingDivisors.c │ ├── Evenarray.c │ ├── Mountain_Scenery.c │ ├── Watermelon.c │ ├── Way Too Long Words.c │ └── petya_and_strings.c ├── Help_Vasilisa_the_Wise_2.cpp ├── Java │ ├── ChatRoom.java │ ├── DiceTower.java │ ├── DimaSerejaProblem.java │ ├── False Numbers.java │ ├── I_Hate_1111(Problem1526B).java │ ├── MajorityElement.java │ ├── Pythagorean_Triples(Problem_1487D).java │ ├── Sleep_Cycle.java │ ├── Twins.java │ └── taxi.java ├── Python │ ├── B_Borze.py │ ├── Deleting_divisors.py │ ├── Indian Coin Change.py │ ├── Unlucky_ticket.py │ └── Way_too_long_words.py └── Round 745 │ └── cqxymcountpermutations.cpp ├── Data Structures ├── Array │ ├── C++ │ │ ├── Array Manipulation.cpp │ │ ├── Arrays - DS.cpp │ │ ├── ChainHashing.cpp │ │ ├── Dynamic Array.cpp │ │ ├── Hashing_with_arrays.cpp │ │ ├── Minimum_swaps_required.cpp │ │ ├── Spiral Order Matrix.cpp │ │ ├── SubArrayWithSum.cpp │ │ ├── intersection of two sorted arrays.cpp │ │ ├── max-absolute-difference.cpp │ │ ├── nextgreatorelement.cpp │ │ └── union of two sorted arrays.cpp │ ├── C │ │ ├── find-pair-with-given-sum-array.c │ │ └── rangeminmax.c │ ├── Java │ │ ├── Rotation_of_Array_by_Kelements.java │ │ ├── Sortarray.java │ │ └── intersection.java │ └── Python │ │ ├── 2D Array.py │ │ ├── AdjacentDifferenceAlgo.py │ │ ├── Intersection of two sorted array.py │ │ ├── ReverseArray.py │ │ ├── Union of two sorted array.py │ │ ├── fenced_matrix.py │ │ └── searching largest and smallest in array.py ├── BinarySearch.java ├── Center_Of_Star_Graph.cpp ├── Collinearity_of_three_points.cpp ├── Delete a given Node when a node is given.cpp ├── FenwickTree.c ├── Generic Swaps Using Templates ├── Graph │ └── C++ │ │ ├── BFS_graph_traversal.cpp │ │ ├── Bipartite_using_DFS.cpp │ │ ├── Detect Cycle In Undirected Graph.cpp │ │ └── cycle_in_undirectedgraph_using_dfs.cpp ├── Indiancoinchange.c ├── Largestsum.java ├── LinkedList │ ├── C++ │ │ ├── Double_linked_list.cpp │ │ ├── Doubly-Linked-List.cpp │ │ ├── Doubly-Linked-List2.cpp │ │ ├── Join Two Linklist.cpp │ │ ├── KReverse.cpp │ │ ├── LinkedList.cpp │ │ ├── Majority Element.cpp │ │ ├── Merge Point of Two Linked List.cpp │ │ ├── Pallindrome_Linked_List.cpp │ │ ├── Reorder_list.cpp │ │ ├── Reverse_Circular_Linkedlist.cpp │ │ ├── Reverse_LinkedList_in_a_group_of_given_size.cpp │ │ ├── Reverse_a_sublist_of_a_list.cpp │ │ ├── SinglyLinkedList.cpp │ │ ├── Sorted_LinkedList_to_BST.cpp │ │ ├── Split_LinkedList.cpp │ │ ├── merge_ll.cpp │ │ └── reverse_LL.cpp │ ├── C │ │ ├── Operations_on_linkedlist.c │ │ ├── PairwiseSwap.c │ │ ├── dequeue.c │ │ ├── odd_even_seggregate.c │ │ └── remove_dup.c │ ├── DoublyLinkedList │ └── Java │ │ └── Reversing_Circular_LinkedList.java ├── MajorityElement.py ├── Max_XOR_of_Two_Array.cpp ├── Merge k sorted linkedlist.py ├── Palindrome Linked List.cpp ├── Queue │ └── C++ │ │ └── Priority_Queue.cpp ├── QueueUsingLL.cpp ├── Reverse a link list using stack.cpp ├── Shortest Distance in Weighted graph using BFS ├── Stack │ ├── C++ │ │ ├── Postfix_Evaluation.cpp │ │ ├── Prefix_Evaluation.cpp │ │ ├── Reverse_ll_using_Stack.cpp │ │ ├── Stack-implementation_using_array.cpp │ │ ├── Stack_operation.cpp │ │ ├── largest_rectangle.cpp │ │ └── prefix_infix.cpp │ ├── C │ │ ├── Infix to Postfix Using Stack in C.c │ │ ├── PrefixtoInfixusingstack.c │ │ ├── array implementation of stack.c │ │ └── histogram.c │ ├── Java │ │ ├── Min_Element_In_Stack.java │ │ ├── StackArray.java │ │ ├── Stack_Using_LinkedList.java │ │ └── infixToPostfix.java │ └── Python │ │ ├── Infix_postfix.py │ │ ├── Prefixtoinfix.py │ │ └── Stack.py ├── Tree │ ├── BST.py │ ├── C++ │ │ ├── BST Binary Tree.cpp │ │ ├── Binary Tree.cpp │ │ ├── Binary_Search_Tree.cpp │ │ ├── Binary_Tree_Symmetric_or_not.cpp │ │ ├── Binary_tree_traversal.cpp │ │ ├── Minimum and maximum value in a Binary Tree.cpp │ │ ├── Red Black Tree (Insertion and Deletion operation).cpp │ │ ├── Top_View_in_Binary_Tree.cpp │ │ ├── Zig-Zag_Binary_Tree_Traversal.cpp │ │ ├── countNodes.cpp │ │ ├── countNodesgreaterthanX.cpp │ │ ├── diameter_of_binary_tree.cpp │ │ └── segment_tree_implementation.cpp │ ├── C │ │ ├── FenwickTree.c │ │ └── Morris.c │ ├── Java │ │ ├── AVL_Tree.java │ │ ├── InOrderTraversal.java │ │ ├── PostOrderTraversal.java │ │ └── PreOrderTraversal.java │ ├── Sum of left leaves.cpp │ ├── Tree_Traversal.cpp │ ├── postorder_traversal.py │ └── sum_replacement.cpp ├── Year_to_min_sec_hour_day.cpp ├── constructing a bst.py ├── copyset.java ├── fixed_parities.cpp ├── gap_method.cpp ├── kthmaxmin.java ├── move_all_negative.cpp ├── npresentornot.c ├── print_the_subset.java ├── symmetric_logo.cpp ├── union_and_intersection.cpp └── xor_challenge.cpp ├── Gfg ├── All_indices.py ├── C++ │ ├── 01 Knapsack.cpp │ ├── Add two fractions.cpp │ ├── Add two numbers represented by linked lists.cpp │ ├── Allocate_minimum_number_of_pages.cpp │ ├── BFS.cpp │ ├── Bitonic_Point.cpp │ ├── Bottom_view_of_a_Tree.cpp │ ├── CHOCOLA–Chocolate.cpp │ ├── Calculate_nCr.cpp │ ├── Chocolate Distribution Problem.cpp │ ├── Coin Change.cpp │ ├── Convert sorted Array to BST.cpp │ ├── Count Inversions.cpp │ ├── Day_of_the_week.cpp │ ├── Delete_without_head_pointer.cpp │ ├── Detect Cycle in Linklist.cpp │ ├── Detect cycle in an undirected graph.cpp │ ├── Detect_Loop_in_linked_list.cpp │ ├── Diagonal Traversal of Binary Tree.cpp │ ├── Diameter of Binary Tree.cpp │ ├── Disjoint_set.cpp │ ├── Duplicate subtree in Binary Tree.cpp │ ├── Egg_Dropping_Puzzle.cpp │ ├── Find the number of islands.cpp │ ├── Find_n_in_array.cpp │ ├── First and last occurrences of x.cpp │ ├── First negative integer in every window of size k .cpp │ ├── Flatten_a_linked_list.cpp │ ├── FriendsPairingProblem.cpp │ ├── Geek_onacci.cpp │ ├── Generate_balanced_parenthesis.cpp │ ├── Good_or_Bad_String.cpp │ ├── Handshakes.cpp │ ├── Height of Binary Tree.cpp │ ├── Huffman Encoding.cpp │ ├── Intersection_Point_in_Y_Shapped_Linked_Lists.cpp │ ├── Job Sequencing Problem.cpp │ ├── Join Two Linklist.cpp │ ├── Kadane's Algorithm.cpp │ ├── LINKED_LIST_RATIO.cpp │ ├── Largest Subtree Sum In a Tree.cpp │ ├── Largest subarray with 0 sum .cpp │ ├── Lastindex.cpp │ ├── Level order traversal.cpp │ ├── M-Coloring Problem.cpp │ ├── Maximise sum in array.cpp │ ├── Maximum of all subarrays of size k.cpp │ ├── Maximum_Index.cpp │ ├── Merge k Sorted Arrays.cpp │ ├── Mirror tree.cpp │ ├── Multiply two linked lists.cpp │ ├── N meetings in one room.cpp │ ├── Next Greater Element.cpp │ ├── PairsWithGivenSum.cpp │ ├── Palindromic partitioning.cpp │ ├── Rat in a Maze Problem.cpp │ ├── Remove duplicate element from sorted Linked List.cpp │ ├── RemoveDuplicatesFromSortedArray.cpp │ ├── Reversearray.cpp │ ├── Rotten Oranges.cpp │ ├── Shortest Path From 1 to n .cpp │ ├── Sieve of Eratosthenes.cpp │ ├── SinglyLinkedListInsertionSort.cpp │ ├── Smallest_window_in_string_containing_all_characters_of_another_string.cpp │ ├── Sort 0s 1s 2s.cpp │ ├── SpiralDisplay.cpp │ ├── Staircase_search.cpp │ ├── Strongly Connected Components.cpp │ ├── Subset Sum Prob.cpp │ ├── Sum_of_nodes_on_the_longest_path_from_root_to_leaf.cpp │ ├── Transitive_Closure_of_Graph.cpp │ ├── Trapping Rain Water.cpp │ ├── Triangular_Number.cpp │ ├── TripletswithZeroSum.cpp │ ├── Union of two sorted arrays.cpp │ ├── Validate_IP.cpp │ ├── Value equal to index value.cpp │ ├── birthday paradox.cpp │ ├── bridge_edge_in_graph.cpp │ ├── calculate_nPr.cpp │ ├── celebrity_problem.cpp │ ├── clone_linked_list_with_next_and_random_pointer.cpp │ ├── count_occurrences_of_element.cpp │ ├── count_squares.cpp │ ├── count_the_triplets.cpp │ ├── countpairwithgivensum.cpp │ ├── dijkstras algo.cpp │ ├── find_largest_sum_contiguous_subarray.cpp │ ├── find_missing_and_repeating.cpp │ ├── first_index_of_array.cpp │ ├── implementation Of Queue.cpp │ ├── implementation of Heap Sort.cpp │ ├── isomorphic_strings.cpp │ ├── k largest elements.cpp │ ├── k-th_smallest_element_in_BST.cpp │ ├── kth_maximum_term_in_an_array.cpp │ ├── largest_BST.cpp │ ├── longest_subarray_with_atmost_k_even_elements.cpp │ ├── majority_elements.cpp │ ├── max_of_size_k_window_using _deque.cpp │ ├── maximum_sum_circular_array.cpp │ ├── median_of_two_sorted_arrays.cpp │ ├── merge_BST.cpp │ ├── merge_k_sorted_linked_lists.cpp │ ├── merge_without_extra_space.cpp │ ├── middle element of stack.cpp │ ├── middle_of_three │ ├── minimize_the_heights.cpp │ ├── minimum-swaps-to-group-all-1s-together.cpp │ ├── minimum_sum.cpp │ ├── minimum_swap_sort.cpp │ ├── minimumjumptoreachend.cpp │ ├── nCr.cpp │ ├── normal_BST_to_Balanced_BST.cpp │ ├── palindrome.cpp │ ├── peak_element.cpp │ ├── postorder_traversal_of_binary_tree_iterative_approach.cpp │ ├── power_of_2.cpp │ ├── printing-solutions-n-queen-problem.cpp │ ├── product_array_puzzle.cpp │ ├── rangeQuery.cpp │ ├── reverse_an_array.cpp │ ├── reverse_link_list_grup.cpp │ ├── rotate matrix.cpp │ ├── search_sorted_matrix.cpp │ ├── sort_by_set_bit.cpp │ ├── spiral_matrix_gfg.cpp │ ├── spiral_print.cpp │ ├── steps_by_knight.cpp │ ├── stock_span_problem.cpp │ ├── swap using bitwise operator.cpp │ ├── top_View_of_Binary_Tree.cpp │ ├── topological_sort.cpp │ ├── trie-insert-and-search.cpp │ ├── triplet_less_than_x.cpp │ ├── uglynum.cpp │ └── word_wrap.cpp ├── C │ ├── Anagaram.c │ ├── Armstrong Number.c │ ├── Next Greater Element.c │ ├── Palindrome Number.c │ ├── Permutation Coefficient.c │ ├── Sort_in_linear_time.c │ ├── Value equal to index value.c │ ├── count-occurence-of-an-element-in-array.c │ ├── firstindex.c │ ├── largest and smallest in array.c │ ├── move_negative_element_to_one_side.c │ ├── neg.c │ └── reverse_array.c ├── DisplayNumberInWord.cpp ├── First_index.java ├── Firstindex.py ├── Java │ ├── Add-1-to-a-number-represented-as-linked-list.java │ ├── All indices of number in an array.java │ ├── AllocateMinimumNumberOfPages.java │ ├── Anagram_Recursion.java │ ├── Armstrong.java │ ├── Bellman_Ford.java │ ├── ChocolateDistribution.java │ ├── CircularTour.java │ ├── Delete_Loop_from_LL.java │ ├── DetectCycleInLinkedlist.java │ ├── Diameter of Binary Tree.java │ ├── Find_Nth_Node_From_End_of_LL.java │ ├── Get_Maxinmum_Maze_Paths.java │ ├── Huffman Encoding.java │ ├── Implementation of Stack.java │ ├── Knapsack Problem.java │ ├── Largestsum.java │ ├── LeftRotationOfArray.java │ ├── Lucky_Person_Alive.java │ ├── MaximizeSum.java │ ├── Merge_two_sorted_LL.java │ ├── Middle of three using minimum comparison.java │ ├── N meetings in one room.java │ ├── Next_greater_Element.java │ ├── Node_Distance_BST.java │ ├── NthNatural.java │ ├── Palindrome String.java │ ├── Parenthesis_Checker.java │ ├── PascalsTriangle.java │ ├── Permutation Coefficient.java │ ├── RearrangingArray.java │ ├── Remove_Duplicate_Elements_from_Unsorted_LL.java │ ├── ReverseAnArray.java │ ├── Rotate Matrix 90 degree.java │ ├── SaddlePoint.java │ ├── Sort_012s.java │ ├── SpiralDisplay.java │ ├── TheKnightsTour.java │ ├── Total_Set_Bits.java │ ├── TowerOfHanoi.java │ ├── TrappingWater.java │ ├── binaryInsertionSort.java │ ├── collinearity0fthreepoints.java │ ├── countEvenDigit_Rec.java │ ├── detect-loop-in-linked-list.java │ ├── implement dfs.java │ ├── rev_arr.java │ ├── reverse-string.java │ ├── reverseLinkedList.java │ ├── rotate matrix.java │ ├── second_largestnum.java │ └── wave_array.java ├── Main.java ├── MedianOfTwoSortedArrayJava.java ├── Minimum spanning tree.cpp ├── Negative_weight_cycle.cpp ├── Python │ ├── Armstrong_no._python.py │ ├── Count occurrences of an element in a sorted array.py │ ├── CountAndSay.py │ ├── Find_n_in_array.py │ ├── Generate_Balanced_parenthesis.py │ ├── InterpolationSearch.py │ ├── Kthlargestelement.py │ ├── Lucky alive person.py │ ├── Maxsubarray.py │ ├── RotateArray.py │ ├── Sort012.py │ ├── Union_of_2_sorted_arrays.py │ ├── anagram.py │ ├── last_index_of_array.py │ ├── max_subtree_sum.py │ ├── merge_two_sorted_array_without_extra_space.py │ ├── merge_two_sorted_linkedlists.py │ ├── pascal.py │ ├── rCircularLinked.py │ ├── range_of_array.py │ ├── search_elements_in_a_matrix.py │ ├── sieve_of_eratosthenes.py │ ├── trapping_rainwater.py │ ├── ugly_num.py │ └── union_arrays.py ├── RotateALinkedList.cpp ├── add two number by linked list.java ├── gold_mine.py ├── maximum xor.java ├── merge_without_extra_space.java ├── negitivenumber.java ├── searchingarray.cpp ├── thirdlargestElement.cpp ├── towerOf.java └── zero.cpp ├── Hackerank ├── C++ │ ├── 10001st prime.cpp │ ├── A Very Big Sum.cpp │ ├── Alternating Characters.cpp │ ├── Angry Professor.cpp │ ├── Array-Manipulation.cpp │ ├── Array_rotation_by_K_elemnt.cpp │ ├── Arrays Left Rotation.cpp │ ├── Athlete Sort.cpp │ ├── Balanced Brackets.cpp │ ├── Beautiful Days at the Movies.cpp │ ├── Between Two Sets.cpp │ ├── Bill Division.cpp │ ├── Binomial Distribution 2.cpp │ ├── Birthday Cake Candles.cpp │ ├── Bit Array.cpp │ ├── Box It.cpp │ ├── Breaking The Records.cpp │ ├── Bubble Sort.cpp │ ├── Camel Case.cpp │ ├── Candies.cpp │ ├── Cats and a Mouse.cpp │ ├── Compare the Triplets.cpp │ ├── Count Occurences Sorted Array BS.cpp │ ├── Counting Sundays.cpp │ ├── Day_Of_a_Programmer.cpp │ ├── Designer PDF Viewer.cpp │ ├── Digit Frequency.cpp │ ├── Divisible Sum Pairs.cpp │ ├── Drawing Book.cpp │ ├── Electronics Shop.cpp │ ├── Find Digits.cpp │ ├── Geometric Distribution 1.cpp │ ├── Geometric Distribution 2.cpp │ ├── Grading Students.cpp │ ├── Highly divisible triangular number.cpp │ ├── Hollow Butterfly.cpp │ ├── Ice Cream Parlor.cpp │ ├── Jumping on the Clouds- Revisited.cpp │ ├── Largest prime factor.cpp │ ├── Largest product in a grid.cpp │ ├── Lattice paths.cpp │ ├── Least Square Regression Line.cpp │ ├── Longest Collatz sequence.cpp │ ├── Magic Square.cpp │ ├── Maps-STL.cpp │ ├── Mars Exploration.cpp │ ├── Maximum path sum I.cpp │ ├── Mini-max Sum.cpp │ ├── New Year Chaos.cpp │ ├── Normal Distribution 1.cpp │ ├── Normal Distribution 2.cpp │ ├── Pearson Correlation Coefficient.cpp │ ├── Plus-Minus.cpp │ ├── Poisson Distribution 2.cpp │ ├── Poisson Distribution.cpp │ ├── Reverse a Doubly Linked List.cpp │ ├── Sets-STL.cpp │ ├── Smallest multiple.cpp │ ├── Sparse Arrays.cpp │ ├── Spearman's Rank Correlation.cpp │ ├── Staircase.cpp │ ├── Strong Password.cpp │ ├── Sum square difference.cpp │ ├── Summation of primes.cpp │ ├── The Central Limit Theorem 3.cpp │ ├── The Central Limit Theorem 2.cpp │ ├── The Central Limit Theorem.cpp │ ├── The Hurdle Race.cpp │ ├── The Time in Words.cpp │ ├── Top-View.cpp │ ├── Variable Sized Arrays.cpp │ ├── Vector-Erase.cpp │ ├── Vector-Sort.cpp │ ├── applesandoranges.cpp │ ├── hackerank_change_time_format.cpp │ ├── hackerrank_applesandoranges.cpp │ ├── hackerrank_birthdaycake.cpp │ └── lucky_number.cpp ├── C │ ├── A Very Big Sum.c │ ├── Anagram.c │ ├── Array Reversal.c │ ├── CamelCase.c │ ├── Cycle Detection.c │ ├── Day of the Programmer.c │ ├── Delete-Duplicate-Value-Node-From-Sorted-LinkedList.c │ ├── Digit Frequency.c │ ├── Divisible Sum Pair.c │ ├── Dynamic Array in C.c │ ├── Equalize the Array.c │ ├── Even Fibonacci numbers.c │ ├── Funny String.c │ ├── Get Node Value.c │ ├── Grading Students.c │ ├── Inserting a Node into a Sorted Doubly Linked List.c │ ├── Jumping on the clouds.c │ ├── Largest palindrome product.c │ ├── Left Rotation array.c │ ├── Left Rotation.c │ ├── Maximum Element.c │ ├── Merge two sorted linkedlist.c │ ├── Migratory Bird.c │ ├── Mini-Max Sum.c │ ├── Multiples of 3 and 5.c │ ├── Number to Words.c │ ├── Permutations of Strings.c │ ├── Post Transition.c │ ├── Print element in Linked List.c │ ├── Printing Pattern Using Loops.c │ ├── Printing Tokens.c │ ├── Querying the Document.c │ ├── Sales by Match.c │ ├── Small Triangles, Large Triangles.c │ ├── Sorting Array of Strings.c │ ├── Structuring the Document.c │ ├── Subarray Division.c │ ├── Time conversion.c │ ├── Variadic functions in C.c │ └── concentric square pattern.c ├── Java │ ├── Camel Case.java │ ├── CutTheSticks.java │ ├── Day-of-the-programmer.java │ ├── Designer_PDF_Viewer.java │ ├── Encryption.java │ ├── Flatland Space stations.java │ ├── Larrys Array.java │ ├── MagicSquare.java │ ├── Pairs.java │ ├── Sparse Arrays.java │ ├── Strong-password.java │ ├── The time in words.java │ └── bigdecimal.java └── Python │ ├── Alternating Characters.py │ ├── Apple and Oranges.py │ ├── Athelete-Sort-Python.py │ ├── Balanced_brackets.py │ ├── Bill Division.py │ ├── Binomial Distribution 1.py │ ├── Birthday Cake Candles.py │ ├── Breaking the records.py │ ├── Caesar Cipher.py │ ├── Digit Power Sum.py │ ├── DigitFreq.py │ ├── Factorial digit sum.py │ ├── Fibonacci Modified.py │ ├── Interquartile Range.py │ ├── Large sum.py │ ├── Largest product in a series.py │ ├── Linear Algebra.py │ ├── LuckyNumber.py │ ├── Mark and Toys.py │ ├── Minimum swaps 2.py │ ├── Multiple Linear Regression.py │ ├── No Idea!.py │ ├── Number line jumps.py │ ├── Pangrams.py │ ├── Power digit sum.py │ ├── Quartiles.py │ ├── Recursive digit sum.py │ ├── Special Pythagorean triplet.py │ ├── Standard Deviation.py │ ├── The Minion Game.py │ ├── Two Strings.py │ ├── Weighted Mean.py │ ├── Words Score.py │ └── smartphone.py ├── LICENSE ├── Leetcode ├── C++ │ ├── .vscode │ │ ├── c_cpp_properties.json │ │ ├── launch.json │ │ └── settings.json │ ├── 01_Matrix.cpp │ ├── 4Sum.cpp │ ├── 55 jump game.cpp │ ├── Add Two Numbers In Linklist.cpp │ ├── AddBinary.cpp │ ├── Best-time-to-buy-and-sell-stocks-III.cpp │ ├── Binary Tree Maximum Path Sum.cpp │ ├── Binary tree level order traversal.cpp │ ├── ClimbStairs.cpp │ ├── Climbing stairs.cpp │ ├── Clone graph.cpp │ ├── Combination Sum IV Solution.cpp │ ├── Combination Sum.cpp │ ├── Combination_Sum.cpp │ ├── Daily temperatures.cpp │ ├── Deepest Leaves Sum.cpp │ ├── Delete a given Node when a node is given.cpp │ ├── Evaluate-reverse-polish-notation.cpp │ ├── Find the dupliacte number.cpp │ ├── Find the longest substring containing vowels at even positions.cpp │ ├── FindAndReplace.cpp │ ├── FindMinimunInRotatedSearchArray_Leetcode.cpp │ ├── First Missing Positive.cpp │ ├── First unique character in a string.cpp │ ├── First_Bad_Version.cpp │ ├── Fruits into Baskets.cpp │ ├── Gas Station greedy.cpp │ ├── Group_Anagrams.cpp │ ├── Hamming_Distance.cpp │ ├── IntToRoman.cpp │ ├── Invert binary tree.cpp │ ├── Kth smallest element in BST.cpp │ ├── KthMissingPositiveNumber.cpp │ ├── LargestNumber_Leetcode.cpp │ ├── Letter_Combinations_Phone_Number.cpp │ ├── Longest common prefix.cpp │ ├── LongestCommonSubsequence.cpp │ ├── Longest_Mountain_Array.cpp │ ├── Longest_valid_parentheses.cpp │ ├── Lowest common ancestor.cpp │ ├── Majority Element.cpp │ ├── Max_Consecutive_Ones_III.cpp │ ├── Maximal Rectangle.cpp │ ├── Maximum_Subarray.cpp │ ├── Minimum Size Subarray Sum.cpp │ ├── Minimum_window.cpp │ ├── Number of 1 bits.cpp │ ├── Number of Islands.cpp │ ├── Open the door.cpp │ ├── Palindrome Linked List.cpp │ ├── Parata-roti.cpp │ ├── Pascal's_Triangle_II.cpp │ ├── Path Sum III.cpp │ ├── Perfect squares.cpp │ ├── Permutation in string.cpp │ ├── Power-Of-Four.cpp │ ├── Rainwater_trapping.cpp │ ├── Regular_Expression_Matching(hard).cpp │ ├── Reorganize Strings.cpp │ ├── Reverse Pairs.cpp │ ├── RomanToInt.cpp │ ├── Search in Rotated Sorted Array.cpp │ ├── Serialize and Deserialize Binary tree.cpp │ ├── Shortest Common Supersequence.cpp │ ├── ShortestCommonSupersequence.cpp │ ├── SkyLine.cpp │ ├── SquareIsEqualToProduct.cpp │ ├── String into Integer.cpp │ ├── Subtree of another tree.cpp │ ├── Sudoku_Solver.cpp │ ├── SwapNodesInPairs.cpp │ ├── Target_Sum.cpp │ ├── Total Hamming Distance.cpp │ ├── Two Sum II - Input array is sorted.cpp │ ├── Two_Sum.cpp │ ├── Valid Anagrams.cpp │ ├── ValidMountainArray.cpp │ ├── Validate bst.cpp │ ├── best_time_to_buy_and_sell_stocks.cpp │ ├── binary_tree_from_preorder_and_inorder.cpp │ ├── cheapest_flight_with_k_stops.cpp │ ├── clone a linked list using random pointer.cpp │ ├── count_and_say.cpp │ ├── first_missing_positive.cpp │ ├── flood_Fill.cpp │ ├── josephus_problem_recursion.cpp │ ├── kids-with-the-greatest-number-of-candies.cpp │ ├── leetcode.cpp │ ├── leetcode_zig_zag.cpp │ ├── longest increasing subsequence.cpp │ ├── maximum_length_of_repeated_subarray.cpp │ ├── next_permutations.cpp │ ├── online_stock_span.cpp │ ├── palindromic_substrings.cpp │ ├── pascal_triangle.cpp │ ├── peakIndexinAMountainArray.cpp │ ├── permutations.cpp │ ├── product_array_except_self.cpp │ ├── remove nth node from end of list.cpp │ ├── trappingRainWater.cpp │ └── valid_sudoku.cpp ├── C │ ├── First Missing Positive.c │ └── Pascal Triangle.c ├── Check If Two String Arrays are Equivalent.java ├── Check if Sentence is Pangram.cpp ├── Combination Sum2.cpp ├── Java │ ├── BFS.java │ ├── BeautifulArray.java │ ├── BinaryTreeFromPreorderAndInorder.java │ ├── Capacity_To_Ship_Packages.java │ ├── CustomSortString.java │ ├── Delete Node in a Linked List.java │ ├── DijsktraAlgo.java │ ├── Excel Sheet Column Title.java │ ├── First_missing_positive_num.java │ ├── Hamming.java │ ├── Linked List Cycle II.java │ ├── Longest_Substring.java │ ├── Longest_valid_parenthesis.java │ ├── Maximum Length of Repeated Subarray.java │ ├── Min_No_Of_Refueling_Stops.java │ ├── Number of 1 Bits.java │ ├── NumberOfIslands.java │ ├── PatchingArray.java │ ├── RodCutting.java │ ├── SetZeroes.java │ ├── SkyLine.java │ ├── StockProblem.java │ ├── SumOfNodesWithEvenValuedGrandparent.java │ ├── Swap Nodes in Pairs.java │ ├── Unique Paths.java │ ├── ZigZagTraversal.java │ ├── contains-duplicate.java │ ├── createTargetArray.java │ ├── minimumWindow.java │ └── next_permutation.java ├── Median of Two Sorted Arrays.java ├── Pow(x,n).py ├── Python │ ├── AddTwoNumbers.py │ ├── KthMissingPositiveNumber.py │ ├── Max Length of Subarray.py │ ├── Next_permutation_of_a_number.py │ ├── Smallest_positive_missingno.py │ ├── String_to_atoi_(Leetcode-Medium).py │ ├── StringtoInteger.py │ ├── Valid_Mountain_Problem.py │ ├── binary_tree_from_inorder_and_preorder.py │ ├── maxrectangle.py │ ├── median_of_2_sorted_arrays.py │ ├── minimum window substring.py │ ├── multiplyStrings.py │ ├── reverseInteger.py │ ├── shortest_supersequence.py │ └── skyline Problem.py ├── RomanToInt.py ├── Task Scheduler ├── WordLadder-II.py ├── check-if-the-sentence-is-pangram.java ├── firstunquiecharacter.java └── maximalrectangle.java ├── Miscellaneous problems ├── C │ └── spiral_matrix.c ├── Java │ ├── ConcatenatedWords │ │ ├── ConcatenatedWords.java │ │ ├── Question - Concatenated Words │ │ └── concatenatedWordsTest.java │ ├── kth_largest_number │ │ └── kThLargestElement.java │ └── numbers.java ├── Number's_last_index_in_array │ └── REC_ARR.c ├── Python │ └── ZeroSumSubarray │ │ └── SubarrayZeroSum.py ├── Template │ └── template.md ├── arraysorting │ └── sort_arr.c └── flipbits.java ├── Operating System └── CPU Scheduler │ ├── Round Robin.cpp │ └── banker algo.cpp ├── README.md ├── codejam ├── C │ └── Impartial Offerings.c └── Java │ └── ReverSort.java └── images ├── Header.png ├── Octat.gif ├── lgmsoc.png ├── manufacturetocat.png └── screenshot-hacktoberfest.digitalocean.com-2021.10.02-02_32_15.png /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | 22 | ### Programming language 23 | 26 | - [ ] C 27 | - [ ] C++ 28 | - [ ] Java 29 | - [ ] Python 30 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/script-addition.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Script Addition 3 | about: Describe this Script you want to add 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | # Aim 11 | 12 | - What is the objective of the Script 13 | 14 | # Details 15 | 16 | - What the features will your script have 17 | 18 | ### Programming language 19 | 22 | - [ ] C 23 | - [ ] C++ 24 | - [ ] Java 25 | - [ ] Python 26 | -------------------------------------------------------------------------------- /.github/auto_assign.yml: -------------------------------------------------------------------------------- 1 | addReviewers: true 2 | 3 | addAssignees: false 4 | 5 | # A list of reviewers to be added to pull requests (GitHub user name) 6 | reviewers: 7 | - Ayush7614 8 | 9 | skipKeywords: 10 | - wip 11 | - draft 12 | -------------------------------------------------------------------------------- /.github/weekly-digest.yml: -------------------------------------------------------------------------------- 1 | # Configuration for weekly-digest - https://github.com/apps/weekly-digest 2 | publishDay: sun 3 | canPublishIssues: true 4 | canPublishPullRequests: true 5 | canPublishContributors: true 6 | canPublishStargazers: true 7 | canPublishCommits: true 8 | -------------------------------------------------------------------------------- /.github/workflows/issue-label.yml: -------------------------------------------------------------------------------- 1 | name: Default 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/checkout@v1 10 | - name: Label Syncer 11 | uses: micnncim/action-label-syncer@v1.3.0 12 | env: 13 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 14 | GITHUB_REPOSITORY: ${{ github.repository }} 15 | with: 16 | manifest: .github/labels.json 17 | prune: false 18 | -------------------------------------------------------------------------------- /Algorithms/Disjoint Set/C++/union_find_algorithm.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ayush7614/Daily-Coding-DS-ALGO-Practice/c2af2a30eb156036bb0ba5f5e8f12094b96051fa/Algorithms/Disjoint Set/C++/union_find_algorithm.cpp -------------------------------------------------------------------------------- /Algorithms/Dynamic Problems/C++/A Frog1.cpp: -------------------------------------------------------------------------------- 1 | //https://atcoder.jp/contests/dp/tasks/dp_a 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int N; 8 | cin >> N; 9 | int ar[N]; 10 | int dp[100001]; 11 | for (int i = 0; i < N; i++) cin >> ar[i]; 12 | for (int i = 0; i < N; i++) { 13 | dp[i] = -1; 14 | } 15 | dp[0] = 0; 16 | dp[1] = abs(ar[0] - ar[1]);//Dp[i] contains minimum score to reach stone i 17 | for (int i = 2; i < N; i++) { 18 | if (dp[i - 1] + abs(ar[i] - ar[i - 1]) < dp[i - 2] + abs(ar[i] - ar[i - 2])) { 19 | dp[i] = dp[i - 1] + abs(ar[i] - ar[i - 1]); 20 | } else { 21 | dp[i] = dp[i - 2] + abs(ar[i] - ar[i - 2]); 22 | } 23 | } 24 | cout << dp[N - 1]; 25 | } 26 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Problems/C++/Fibonacci numbers.cpp: -------------------------------------------------------------------------------- 1 | //Fibonacci Series using Recursion 2 | #include 3 | using namespace std; 4 | 5 | int fib(int n) 6 | { 7 | if (n <= 1) 8 | return n; 9 | return fib(n-1) + fib(n-2); 10 | } 11 | 12 | int main () 13 | { 14 | int n = 9; 15 | cout << fib(n); 16 | getchar(); 17 | return 0; 18 | } 19 | 20 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Problems/C++/Friends Pairing .cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | int main(){ 7 | int n; 8 | cin>>n; 9 | vector dp(n+1,0); 10 | dp[0]=1; 11 | dp[1]=1; 12 | for(int i=2;i<=n;i++){ 13 | dp[i]=dp[i-1]+(i-1)*dp[i-2]; 14 | } 15 | cout< 5 | using namespace std; 6 | 7 | int getNoOfWays(int n) 8 | { 9 | // Base case 10 | if (n == 0) 11 | return 0; 12 | if (n == 1) 13 | return 1; 14 | 15 | return getNoOfWays(n - 1) + getNoOfWays(n - 2); 16 | } 17 | 18 | // Driver Function 19 | int main() 20 | { 21 | cout << getNoOfWays(4) << endl; 22 | cout << getNoOfWays(3); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Algorithms/Dynamic Problems/Python/Print Fibonacci sequence using 2 variables.py: -------------------------------------------------------------------------------- 1 | # Simple Python3 Program to 2 | # print Fibonacci sequence 3 | 4 | def fib(n): 5 | a = 0 6 | b = 1 7 | if (n >= 0): 8 | print(a, end=' ') 9 | if (n >= 1): 10 | print(b, end=' ') 11 | for i in range(2, n+1): 12 | c = a + b 13 | print(c, end=' ') 14 | a = b 15 | b = c 16 | 17 | # Driver code 18 | fib(9) 19 | 20 | -------------------------------------------------------------------------------- /Algorithms/Miscellaneous/C++/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 | Sample Output: 34 | Example 1:- 2 35 | Example 2:- 8 36 | */ -------------------------------------------------------------------------------- /Algorithms/Miscellaneous/C++/PrimeFactorization.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void sievePrimeFactor(int n) 5 | { 6 | int arr[n+1]={0}; 7 | for(int i=2;i<=n;i++) 8 | arr[i]=i; 9 | for(int i=2;i*i<=n;i++) 10 | { 11 | for(int j=i;j<=n;j++) 12 | { 13 | if(arr[j]==j) 14 | { 15 | if(j%i==0) 16 | arr[j]=i; 17 | } 18 | } 19 | } 20 | 21 | while(n!=1) 22 | { 23 | cout< 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 : "< 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | long long int a[10],n,i,sum=0; 9 | scanf("%lld",&n); 10 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | int a[1000],n=1,i=0,result=0; 8 | scanf("%d",&n); 9 | for(i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | int solveMeFirst(int a, int b) { 8 | return a+b; 9 | } 10 | int main() { 11 | int num1,num2; 12 | scanf("%d %d",&num1,&num2); 13 | int sum; 14 | sum = solveMeFirst(num1,num2); 15 | printf("%d",sum); 16 | return 0; 17 | } 18 | 19 | 20 | -------------------------------------------------------------------------------- /Algorithms/Miscellaneous/Python/Coin Change.py: -------------------------------------------------------------------------------- 1 | # Recursive Python3 program for 2 | # coin change problem. 3 | 4 | # Returns the count of ways we can sum 5 | # S[0...m-1] coins to get sum n 6 | def count(S, m, n ): 7 | 8 | # If n is 0 then there is 1 9 | # solution (do not include any coin) 10 | if (n == 0): 11 | return 1 12 | 13 | # If n is less than 0 then no 14 | # solution exists 15 | if (n < 0): 16 | return 0; 17 | 18 | # If there are no coins and n 19 | # is greater than 0, then no 20 | # solution exist 21 | if (m <=0 and n >= 1): 22 | return 0 23 | 24 | # count is sum of solutions (i) 25 | # including S[m-1] (ii) excluding S[m-1] 26 | return count( S, m - 1, n ) + count( S, m, n-S[m-1] ); 27 | 28 | # Driver program to test above function 29 | arr = [1, 2, 3] 30 | m = len(arr) 31 | print(count(arr, m, 4)) 32 | 33 | -------------------------------------------------------------------------------- /Algorithms/Miscellaneous/Python/N-th Tribonacci Number.py: -------------------------------------------------------------------------------- 1 | def Tribonacci_Number(n): 2 | if n == 0 : 3 | return 0 4 | elif n == 1 or n == 2 : 5 | return 1 6 | else : 7 | return (Tribonacci_Number(n-1) + Tribonacci_Number(n-2) + Tribonacci_Number(n-3)) 8 | 9 | N = input("Enter n for find nth Tribonacci Number : ") 10 | 11 | print(N,"th Tribonacci Number is : ",Tribonacci_Number(int(N))) 12 | -------------------------------------------------------------------------------- /Algorithms/Miscellaneous/Python/Russian peasant multiplication.py: -------------------------------------------------------------------------------- 1 | # Function to perform Russian peasant multiplicatioin 2 | def russian_peasant_multiplication(a, b): 3 | # Initialize product as 0 4 | product = 0 5 | # Loop to maintain b >= 1 6 | while b > 0: 7 | # When b is an odd number: 8 | if b % 2 != 0: 9 | # a is added to the product 10 | product += a 11 | # a is doubled 12 | a = a * 2 13 | # b is halved 14 | b = b // 2 15 | # Returns the prooduct between a and b 16 | return product 17 | 18 | # a and b are to be multipilied 19 | a = 54 20 | b = 75 21 | # Prints the product of a and b using russian_peasant_multiplication() 22 | print(russian_peasant_multiplication(a, b)) -------------------------------------------------------------------------------- /Algorithms/Miscellaneous/Python/TowerOfHanoi.py: -------------------------------------------------------------------------------- 1 | # Creating a recursive function 2 | def tower_of_hanoi(disks, source, auxiliary, target): 3 | if(disks == 1): 4 | print('Move disk 1 from rod {} to rod {}.'.format(source, target)) 5 | return 6 | # function call itself 7 | tower_of_hanoi(disks - 1, source, target, auxiliary) 8 | print('Move disk {} from rod {} to rod {}.'.format(disks, source, target)) 9 | tower_of_hanoi(disks - 1, auxiliary, source, target) 10 | 11 | 12 | disks = int(input('Enter the number of disks: ')) 13 | # We are referring source as A, auxiliary as B, and target as C 14 | tower_of_hanoi(disks, 'A', 'B', 'C') # Calling the function 15 | -------------------------------------------------------------------------------- /Algorithms/Miscellaneous/Python/partition_problem.py: -------------------------------------------------------------------------------- 1 | def subsetSum(A, n, sum): 2 | 3 | if sum == 0: 4 | return True 5 | 6 | if n < 0 or sum < 0: 7 | return False 8 | 9 | include = subsetSum(A, n - 1, sum - A[n]) 10 | 11 | if include: 12 | return True 13 | 14 | exclude = subsetSum(A, n - 1, sum) 15 | 16 | return exclude 17 | 18 | 19 | def partition(A): 20 | 21 | total = sum(A) 22 | 23 | return (total & 1) == 0 and subsetSum(A, len(A) - 1, total/2) 24 | 25 | 26 | if __name__ == '__main__': 27 | 28 | A = [7, 3, 1, 5, 4, 8] 29 | 30 | print(partition(A)) 31 | -------------------------------------------------------------------------------- /Algorithms/Searching and Sorting/C++/BubbleSort.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ayush7614/Daily-Coding-DS-ALGO-Practice/c2af2a30eb156036bb0ba5f5e8f12094b96051fa/Algorithms/Searching and Sorting/C++/BubbleSort.exe -------------------------------------------------------------------------------- /Algorithms/Searching and Sorting/C++/Insertion Sort using Call By Reference method.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl '\n' 3 | using namespace std; 4 | 5 | void arraySort(int *arr, int *n) 6 | { 7 | int temp,j,i = 1; 8 | arr++; 9 | while(i<*n) 10 | { 11 | j=1; 12 | temp = *arr; 13 | while(temp<*(arr-j) && (i-j)>=0) 14 | { 15 | int k = *(arr-j); 16 | *(arr-j+1) = k; 17 | j++; 18 | } 19 | *(arr-j+1) = temp; 20 | i++; 21 | arr++; 22 | } 23 | } 24 | 25 | int main() 26 | { 27 | int n; 28 | cout<<"Enter number of elements in array: "; 29 | cin>>n; 30 | 31 | int arr[n]; 32 | for(int i=0 ; i>arr[i]; 36 | } 37 | arraySort(&arr[0], &n); 38 | 39 | for(int i=0 ; i 2 | using namespace std; 3 | 4 | bool BinarySearch(int arr[], int l, int r, int k) 5 | { 6 | int m; 7 | 8 | while(r-l>1) 9 | { 10 | m = l+(r-l)/2; 11 | 12 | if(arr[m]<=k) 13 | l = m; 14 | else 15 | r = m; 16 | } 17 | 18 | if(arr[l] == k) 19 | return l; 20 | if(arr[r] == k) 21 | return r; 22 | else 23 | return 0; 24 | } 25 | 26 | int main() 27 | { 28 | int n; 29 | cin>>n; 30 | int a[n]; 31 | 32 | for(int i=0;i>a[i]; 34 | 35 | int u; // No u want to Search 36 | cin>>u; 37 | 38 | if(BinarySearch(a,0,n-1,u)) 39 | cout<<"Number is Present"; 40 | else 41 | cout<<"Number is not Present"; 42 | } 43 | /* 44 | Input: 45 | 4 46 | 1 5 2 6 47 | 2 48 | Output :- Number is Present 49 | */ 50 | 51 | /* 52 | Time Complexity :- O(log(n)) 53 | */ 54 | -------------------------------------------------------------------------------- /Algorithms/Searching and Sorting/C++/Wave sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void swap(int arr[], int i, int j){ 5 | 6 | int temp=arr[i]; 7 | arr[i]=arr[j]; 8 | arr[j]=temp; 9 | } 10 | 11 | void wavesort(int arr[], int n){ 12 | 13 | for(int i=1;i arr[i-1]){ 15 | swap(arr,i,i-1); 16 | } 17 | if(arr[i]>arr[i+1] && i<=n-2){ 18 | swap(arr,i,i+1); 19 | } 20 | } 21 | } 22 | int main(){ 23 | 24 | int n; 25 | cin>>n; 26 | int arr[n]; 27 | for (int i=0;i>arr[i]; 29 | } 30 | wavesort(arr,n); 31 | for(int i=0;i 6 | using namespace std; 7 | 8 | int search(int arr[], int n, int x) 9 | { 10 | int i; 11 | for (i = 0; i < n; i++) 12 | if (arr[i] == x) 13 | return i; 14 | return -1; 15 | } 16 | 17 | // Driver code 18 | int main(void) 19 | { 20 | int arr[] = { 2, 3, 4, 10, 40 }; 21 | int x = 10; 22 | int n = sizeof(arr) / sizeof(arr[0]); 23 | 24 | // Function call 25 | int result = search(arr, n, x); 26 | (result == -1) 27 | ? cout << "Element is not present in array" 28 | : cout << "Element is present at index " << result; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Algorithms/Searching and Sorting/C/Bubble Sort.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void bubbleSort(int arr[], int n) 4 | { 5 | int i,j,temp; 6 | for(i=0 ; i arr[j+1]) 11 | { 12 | temp = arr[j]; 13 | arr[j] = arr[j+1]; 14 | arr[j+1] = temp; 15 | } 16 | } 17 | } 18 | for(i=0 ; i 2 | 3 | void arraySort(int *arr, int *n) 4 | { 5 | int temp,j,i = 1; 6 | arr++; 7 | while(i<*n) 8 | { 9 | j=1; 10 | temp = *arr; 11 | while(temp<*(arr-j) && (i-j)>=0) 12 | { 13 | int k = *(arr-j); 14 | *(arr-j+1) = k; 15 | j++; 16 | } 17 | *(arr-j+1) = temp; 18 | i++; 19 | arr++; 20 | } 21 | } 22 | 23 | int main() 24 | { 25 | int i,n; 26 | printf("Enter number of elements in array: "); 27 | scanf("%d",&n); 28 | 29 | int arr[n]; 30 | for(i=0 ; i arr[j + 1] : 10 | arr[j], arr[j + 1] = arr[j + 1], arr[j] #swapping 11 | 12 | # Driver Code :- 13 | a = [5, 8, 1, 9, 3, 0] 14 | 15 | bubbleSort(a) 16 | print ("Sorted array -> :") 17 | for i in range(len(a)): 18 | print ("% d" % a[i]), 19 | 20 | # Input : - 5,8,1,9,3,0 21 | # Output :- 0,1,3,5,8,9 22 | 23 | # Time complexity :- O(n) 24 | -------------------------------------------------------------------------------- /Algorithms/Searching and Sorting/Python/Bubble_sort._python.py: -------------------------------------------------------------------------------- 1 | #BUBBLE SORTING: 2 | nlist=eval(input("enter a list")) 3 | for passnum in range(len(nlist)-1,0,-1): 4 | for i in range(passnum): 5 | if nlist[i]>nlist[i+1]: 6 | temp = nlist[i] 7 | nlist[i] = nlist[i+1] 8 | nlist[i+1] = temp 9 | print(nlist) 10 | 11 | #enter a list[5,6,9,34,1,0,4] 12 | #[0, 1, 4, 5, 6, 9, 34] 13 | -------------------------------------------------------------------------------- /Codechef/C++/AND Plus OR(ANDOR).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | 5 | #define int long long 6 | 7 | signed main() { 8 | // your code goes here 9 | int t; 10 | cin>>t; 11 | while(t--) 12 | { 13 | int x; 14 | cin>>x; 15 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | float balance; 6 | int amount; 7 | 8 | 9 | cin>>amount>>balance; 10 | 11 | 12 | if(amount%5==0 && amount<=balance-0.50){ 13 | balance=balance-(amount+0.50); 14 | cout< 4 | 5 | using namespace std; 6 | 7 | int main() { 8 | // Read the number of test cases. 9 | int T; 10 | scanf("%d", &T); 11 | while (T--) { 12 | // Read the input a, b 13 | int a, b; 14 | scanf("%d %d", &a, &b); 15 | 16 | // Compute the ans. 17 | int ans = a + b; 18 | printf("%d\n", ans); 19 | } 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /Codechef/C++/Arrange the Students (ARRSTUD).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | string s1; 15 | cin>>s1; 16 | ll counter=1; 17 | for(ll i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | int arr[n]; 13 | for(int i=0;i>arr[i]; 15 | int counterZero=0 , counterOne = 0; 16 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | long long t; 7 | cin>>t; 8 | while(t--!=0) 9 | { 10 | long long d,D,P,Q,sum=0; 11 | cin>>D>>d>>P>>Q; 12 | long long k=D/d; 13 | if(D%d==0) 14 | { 15 | sum+=d*(P*k+(k*(k-1)/2)*Q); 16 | } 17 | else 18 | { 19 | sum+=d*(P*k+(k*(k-1)/2)*Q); 20 | // cout< 2 | #define all(x) x.begin(),x.end() 3 | using ll = long long int; 4 | using namespace std; 5 | ll getPower(ll a, ll b){ 6 | static ll mod = 1000000007; 7 | if(b==0)return 1; 8 | if(b==1)return a; 9 | 10 | if(b%2==0){ 11 | ll ans = getPower(a,b/2); 12 | return (ans * ans) % mod; 13 | } 14 | else { 15 | ll ans = getPower(a,(b-1)/2); 16 | return ((a*ans)%mod*ans)%mod; 17 | } 18 | } 19 | int main() { 20 | 21 | int t; cin >>t ; 22 | while(t--){ 23 | ll a,b,temp; 24 | cin >> a >> b; 25 | temp = getPower(2,a)-1; 26 | cout << getPower(temp,b) << endl; 27 | } 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Codechef/C++/Body Mass Index (BMI).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int h,m; 11 | cin>> m >>h; 12 | int bmi=m/(h*h); 13 | if(bmi<=18) 14 | cout<<"1"< 2 | using namespace std; 3 | #define bruh main 4 | int bruh(){ 5 | int n; 6 | cin>>n; 7 | vectorv; 8 | int input; 9 | for(int i=0;i<=n;i++) 10 | { 11 | cin>>input; 12 | v.push_back(input); 13 | } 14 | sort(v.begin(),v.end()); 15 | cout< 2 | #include 3 | void is_armstrong(int number) 4 | { 5 | int num, lastDigit, digits, sum, i; 6 | 7 | 8 | 9 | 10 | for(i=0; i<=number; i++) 11 | { 12 | sum = 0; 13 | 14 | 15 | num = i; 16 | 17 | 18 | digits = (int) log10(num) + 1; 19 | 20 | 21 | while(num > 0) 22 | { 23 | 24 | lastDigit = num % 10; 25 | 26 | 27 | sum = sum + ceil(pow(lastDigit, digits)); 28 | 29 | 30 | num = num / 10; 31 | } 32 | 33 | 34 | if(i == sum) 35 | { 36 | printf(" %d", i); 37 | } 38 | 39 | } 40 | 41 | } 42 | int main() { 43 | int x; 44 | scanf("%d",&x); 45 | is_armstrong(x); 46 | return 0; 47 | } -------------------------------------------------------------------------------- /Codechef/C++/BugCrush 2 Question 3 (BUGC203).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int gcd(int x, int y) 4 | { 5 | if(x == 0) 6 | return y; 7 | return gcd(y%x, x); 8 | } 9 | int GCD_Helper(vector v, int n) 10 | { 11 | int ans = v[0]; 12 | for (int i = 1; i < n; i++) 13 | { 14 | ans = gcd(v[i], ans); 15 | if(ans==1) 16 | return 1; 17 | } 18 | return ans; 19 | } 20 | int main() 21 | { 22 | int n; 23 | cin>>n; 24 | vector v; 25 | int input; 26 | for(int i=0;i<=n;i++) 27 | { 28 | cin>>input; 29 | v.push_back(input); 30 | } 31 | 32 | 33 | 34 | cout << GCD_Helper(v, n) << endl; 35 | return 0; 36 | } -------------------------------------------------------------------------------- /Codechef/C++/BugCrush 2 Question 4 (BUGC204).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | struct Node 4 | { 5 | int data; 6 | struct Node* next; 7 | }; 8 | int count(struct Node* head) 9 | { 10 | if (head == NULL) 11 | return 0; 12 | return 1+count(head->next); 13 | } 14 | void add(struct Node** header, int datum) 15 | { 16 | struct Node* point = (struct Node*) malloc(sizeof(struct Node)); 17 | point->data = datum; 18 | point->next = (*header); 19 | (*header) = point; 20 | } 21 | int main() 22 | { 23 | struct Node* head = NULL; 24 | add(&head, 1); 25 | add(&head, 3); 26 | add(&head, 1); 27 | add(&head, 2); 28 | add(&head, 1); 29 | printf("Count of nodes is %d", count(head)); 30 | return 0; 31 | } -------------------------------------------------------------------------------- /Codechef/C++/BugCrush 2 Question 7 (BUGC207).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | long long maximumNum(long A,long B,long C) 4 | { 5 | long long num = 0; 6 | if (C - C % A + B <= C) { 7 | 8 | num = C - C % A + B; 9 | } 10 | else { 11 | num = C - C % A - (A - B); 12 | } 13 | return num; 14 | } 15 | int main() 16 | { 17 | long A = 10; 18 | long B = 5; 19 | long C = 15; 20 | 21 | cout << maximumNum(A, B , C); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Codechef/C++/Bytelandian gold coins.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | using ll = long long; 7 | 8 | unordered_map dp; 9 | 10 | ll profit(ll n) { 11 | if (n == 0LL) { 12 | return n; 13 | } 14 | if (dp.find(n) != dp.end()) { 15 | return dp[n]; 16 | } 17 | 18 | ll ans = max(n, profit(n / 2LL) + profit(n / 3LL) + profit(n / 4LL)); 19 | return dp[n] = ans; 20 | } 21 | 22 | int main() { 23 | ios_base::sync_with_stdio(0); 24 | cin.tie(0); 25 | 26 | ll n; 27 | dp[0LL] = 0LL; 28 | while (cin >> n) { 29 | cout << profit(n) << '\n'; 30 | } 31 | 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Codechef/C++/Chef and Dice (SDICE).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | ll n; 11 | cin>>n; 12 | ll sum=0; 13 | sum = (n/4)*44; 14 | ll rem =n%4; 15 | if(n>=4) 16 | { 17 | if(rem==0) 18 | sum +=16; 19 | else if(rem==1) 20 | sum+=32; 21 | else if(rem==2) 22 | sum+=44; 23 | else if(rem==3) 24 | sum+=55; 25 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | string s; 11 | cin>> s; 12 | int count=0; 13 | for(int i=0;i 2 | using namespace std; 3 | #define ll long long int 4 | 5 | int main() 6 | { 7 | ios_base::sync_with_stdio(false); 8 | cin.tie(NULL); 9 | cout.tie(NULL); 10 | ll t; 11 | cin>>t; 12 | while(t--) 13 | { 14 | ll n,ans=1; 15 | cin>>n; 16 | for(ll i=1;i<=n;i++) 17 | ans*=i; 18 | cout< 6 | using namespace std; 7 | #define ll long long 8 | void solve() 9 | { 10 | int a[3]; 11 | for(int i=0;i<3;i++) 12 | cin>>a[i]; 13 | sort(a,a+3); 14 | cout<>t; 23 | while(t--) 24 | { 25 | solve(); 26 | } 27 | return 0; 28 | } 29 | 30 | // Sample input/output 31 | 32 | // Sample Input 1 33 | // 2 34 | // 4 2 8 35 | // 10 14 18 36 | 37 | // Sample Output 1 38 | // 12 39 | // 32 -------------------------------------------------------------------------------- /Codechef/C++/Coldplay (SLOOP).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | #define loop(i,a,b) for(int i=a;i<=(b);i++) 5 | #define ff first 6 | #define ss second 7 | #define vi vector 8 | 9 | 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | cout.tie(NULL); 15 | ll t; 16 | cin>>t; 17 | while(t--) 18 | { 19 | ll m,s; 20 | cin>>m>>s; 21 | if(s>m) 22 | cout<<0< 2 | using namespace std; 3 | #define ll long long int 4 | #define loop(i,a,b) for(int i=a;i<(b);i++) 5 | #define ff first 6 | #define ss second 7 | #define vi vector 8 | 9 | ll isDivisible(ll n) 10 | { 11 | if(n%5==0) 12 | { 13 | if(n%15==0) 14 | { 15 | if(n%75==0) 16 | return 3; 17 | return 2; 18 | } 19 | return 1; 20 | } 21 | return 0; 22 | } 23 | 24 | int main() 25 | { 26 | ios_base::sync_with_stdio(false); 27 | cin.tie(NULL); 28 | cout.tie(NULL); 29 | ll t; 30 | cin>>t; 31 | while(t--) 32 | { 33 | ll n; 34 | cin>>n; 35 | cout< 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | // your code goes here 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n; 12 | cin>>n; 13 | cout<<(int)sqrt(n)< 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | // Read the number of test cases. 7 | int T; 8 | scanf("%d", &T); 9 | while (T--) { 10 | // Read the input a, b 11 | int a, b; 12 | scanf("%d %d", &a, &b); 13 | 14 | // Compute the ans. 15 | // Complete the below line. 16 | int ans = a%b; 17 | printf("%d\n", ans); 18 | } 19 | 20 | return 0; 21 | } -------------------------------------------------------------------------------- /Codechef/C++/Food Chain (FODCHAIN).cpp: -------------------------------------------------------------------------------- 1 | // Problem link: https://www.codechef.com/START7C/problems/FODCHAIN 2 | // In this problem we have to divide e/k repeatedly until e becomes zero 3 | // Maintain a counter to find out when e becomes zero 4 | 5 | #include 6 | using namespace std; 7 | #define ll long long 8 | void solve() 9 | { 10 | ll int e,k,a=0; // here a is counter 11 | cin>>e>>k; 12 | while(e>0) 13 | { 14 | e=e/k; 15 | a++; 16 | } 17 | cout<>t; 25 | while(t--) 26 | { 27 | solve(); 28 | } 29 | return 0; 30 | } 31 | 32 | // Sample input/output 33 | 34 | // Sample Input 1 35 | // 3 36 | // 5 3 37 | // 6 7 38 | // 10 2 39 | 40 | // Sample Output 1 41 | // 2 42 | // 1 43 | // 4 -------------------------------------------------------------------------------- /Codechef/C++/Fuel Mountains (MFUEL).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | int arr[n]; 13 | for(int i=0;i>arr[i]; 16 | } 17 | int sum=0, maxSum=INT_MIN; 18 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin >>n; 12 | int arr[n]; 13 | for(int i=0;i> arr[i]; 15 | int dist=0; 16 | int fuel=arr[0]; 17 | for(int i=1;i0;i++) 18 | { 19 | fuel--; 20 | fuel +=arr[i]; 21 | dist++; 22 | } 23 | cout<<(dist + fuel)< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n ; 12 | int a[n]; 13 | int sum=0 , maxNew=0; 14 | for(int i=0;i>a[i]; 17 | sum +=a[i]; 18 | maxNew=max(maxNew , a[i]); 19 | } 20 | if((sum - maxNew) > maxNew) 21 | cout<<"YES"< 2 | #include 3 | using namespace std; 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int a ,b ,c; 11 | cin>>a>>b>>c; 12 | int sm=(a+1)%c; 13 | if(b%c==0 || b%c==sm) 14 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int n; 9 | cin>>n; 10 | cout<<(n+1)/2< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | 11 | long int n; 12 | cin>>n; 13 | int s=0,m=1; 14 | while(n>=s) 15 | { 16 | s=pow(2,m); 17 | m++; 18 | } 19 | long int a=pow(2,m-2)-1; 20 | long int sum=s-n; 21 | long int ans=a*(a+sum); 22 | cout< 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | // your code goes here 9 | long long int t, c, x, f, ma, i, temp, p, a, b; 10 | cin >> t; 11 | while (t--) 12 | { 13 | cin >> c; 14 | f = 0; 15 | f = int(log2(c)); 16 | p = pow(2, f); 17 | a = p - 1; 18 | b = a ^ c; 19 | cout << a * b << endl; 20 | } 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /Codechef/C++/Kid & Table (TABLE).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | #define loop(i,a,b) for(int i=a;i<(b);i++) 5 | #define ff first 6 | #define ss second 7 | #define vi vector 8 | 9 | 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | cout.tie(NULL); 15 | ll n; 16 | cin>>n; 17 | loop(i,1,10) 18 | cout< "; 19 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | long long T; 7 | cin>>T; 8 | for(int i=1; i<=T; i++) 9 | { 10 | long long N,x,k; 11 | cin>>N>>x>>k; 12 | if (x%k==0 || (N+1-x)%k==0) 13 | cout<<"YES"< 2 | using namespace std; 3 | #define ll long long int 4 | #define loop(i,a,b) for(int i=a;i<(b);i++) 5 | #define ff first 6 | #define ss second 7 | #define vi vector 8 | 9 | 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | cout.tie(NULL); 15 | ll t; 16 | cin>>t; 17 | while(t--) 18 | { 19 | ll n; 20 | cin>>n; 21 | ll ans=0; 22 | while(n!=0) 23 | { 24 | if(n%2==1) 25 | ans++; 26 | n=n/2; 27 | } 28 | cout< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | 6 | int32_t main() 7 | { 8 | ios_base::sync_with_stdio(false); 9 | cin.tie(0); 10 | int t;cin>>t; 11 | while(t--) 12 | { 13 | int n, m;cin>>n>>m; 14 | int count_of_pair = 0; 15 | vector modular_equation(n+1, 1); 16 | for(int a = 2;a<=n;a++) 17 | { 18 | int x = m%a; 19 | count_of_pair += modular_equation[x]; 20 | for(int b = x;b<=n;b+=a) 21 | { 22 | modular_equation[b]++; 23 | } 24 | } 25 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,h,x; 7 | cin>> n >> h >>x; 8 | int arr[n]; 9 | for(int i=0;i>arr[i]; 12 | } 13 | 14 | bool ans=0; 15 | for(int j=0;j 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,m; 11 | cin>>n>>m; 12 | int arr[n]; 13 | for(int i=0;i>arr[i]; 16 | } 17 | int newArr[m+1]; 18 | 19 | for(int i=1;i<=m;i++) 20 | { 21 | newArr[i]=0; 22 | } 23 | for(int i=0;i 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | long long int t, n, s, c, tc; 9 | cin >> t; 10 | while (t--) 11 | { 12 | cin >> n; 13 | s = 0; 14 | c = 1; 15 | tc = 0; 16 | while (tc != n) 17 | { 18 | if (n - tc < c) 19 | { 20 | s = s + (n - tc) * c; 21 | tc = n; 22 | } 23 | else 24 | { 25 | s = s + c * c; 26 | tc = tc + c; 27 | } 28 | c++; 29 | } 30 | cout << s << endl; 31 | } 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Codechef/C++/Pawri Meme (PAWRI).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | long long int t; 7 | cin>>t; 8 | while(t--){ 9 | string s; 10 | cin>>s; 11 | 12 | int n=s.size(); 13 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int r,o,c; 7 | cin>>r>>o>>c; 8 | int extraScore = (20-o) * 6 * 6; 9 | if((extraScore + c) > r) 10 | cout<<"YES"< 2 | using namespace std; 3 | #define ll long long int 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | ll a,b; 11 | cin>>a>>b; 12 | ll ans=a|b; 13 | cout< 2 | using namespace std; 3 | int score[2]={0,0}; 4 | 5 | void comparison() 6 | { 7 | int a[3]; 8 | int b[3]; 9 | for(int i=0;i<3;i++) 10 | { 11 | cin>>a[i]; 12 | } 13 | for(int i=0;i<3;i++) 14 | { 15 | cin>>b[i]; 16 | } 17 | int i; 18 | for(i=0;i<3;i++) 19 | { 20 | if(a[i]>b[i]) 21 | { 22 | score[0]++; 23 | } 24 | else if(b[i]>a[i]) 25 | { 26 | score[1]++; 27 | } 28 | else if(a[i]==b[i]) 29 | { 30 | continue; 31 | } 32 | } 33 | 34 | } 35 | 36 | int main() { 37 | 38 | comparison(); 39 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | // your code goes here 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | long long int n,rev=0; 13 | cin>>n; 14 | while(n>0) 15 | { 16 | int x=n%10; 17 | rev=rev*10 + x; 18 | n=n/10; 19 | } 20 | cout< 2 | using namespace std; 3 | int main(){ 4 | int t; 5 | cin>>t; 6 | while(t--){ 7 | int a,b,c,d; 8 | cin>>a>>b>>c>>d; 9 | cout<<(c/a)+(d/b)< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | 7 | int t; 8 | cin>>t; 9 | while(t--) 10 | { 11 | int n,k; 12 | cin>>n >>k; 13 | if(k==0) 14 | cout< 2 | using namespace std; 3 | #define ll long long 4 | int main() 5 | { 6 | vector v; // Initialise vector with name v 7 | ll int a,n; 8 | cin>>n; // n denotes total number of potential customers. 9 | for(int i=0;i>a; // taking the budget of each cutomer and pushing them into vector v 12 | v.push_back(a); 13 | } 14 | sort(v.begin(),v.end()); // sorting the vector 15 | for(int i=0;i 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | 6 | int32_t main() 7 | { 8 | int t; 9 | cin >> t; 10 | while (t--) 11 | { 12 | int p, x, y; 13 | cin >> p >> x >> y; 14 | int ans = 0; 15 | ans = x + (100 - p) * y; 16 | ans = ans * 10; 17 | cout << ans << endl; 18 | } 19 | return 0; 20 | } -------------------------------------------------------------------------------- /Codechef/C++/Split the String (SPLITIT).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | 11 | int n; 12 | string s; 13 | cin>> n >>s; 14 | char last=s[n-1]; 15 | bool ans=0; 16 | for(int i=0;i 2 | using namespace std; 3 | #define ll long long int 4 | #define loop(i,a,b) for(int i=a;i<(b);i++) 5 | #define ff first 6 | #define ss second 7 | #define vi vector 8 | 9 | 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | cout.tie(NULL); 15 | string s; 16 | cin>>s; 17 | vector v; 18 | sort(s.begin(),s.end()); 19 | do{ 20 | v.push_back(s); 21 | }while(next_permutation(s.begin(),s.end())); 22 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,k,counter=0; 11 | string s; 12 | cin>>n>>k>>s; 13 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | long long int n,sum=0; 11 | cin>>n; 12 | while(n>0) 13 | { 14 | int x=n%10; 15 | sum+=x; 16 | n=n/10; 17 | } 18 | cout< 14 | #define ll unsigned long int 15 | using namespace std; 16 | 17 | int main() 18 | { 19 | ll test; 20 | cin >> test; 21 | for (ll k = 0; k < test; k++) 22 | { 23 | double quantity, price; 24 | cin >> quantity >> price; 25 | if (quantity > 1000) 26 | { 27 | double discount = price * 0.1; 28 | price = price - discount; 29 | } 30 | double result = quantity * price; 31 | cout << fixed << setprecision(6) << result << endl; 32 | } 33 | 34 | return 0; 35 | } 36 | -------------------------------------------------------------------------------- /Codechef/C++/Valid Pair (SOCKS1).cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long int 4 | int main() { 5 | 6 | int a ,b,c; 7 | cin>>a>>b>>c; 8 | if((a>= 1 && a<=10) && (b>=1 && b<=10) && (c>=1 && c<=10)) 9 | { 10 | if(a==b && b==c) 11 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>> n; 12 | int arr[n],sum=0; 13 | for(int i=0;i> arr[i]; 16 | sum += arr[i]; 17 | } 18 | if(sum>=0) 19 | cout<<"YES"< 2 | using namespace std; 3 | int main() 4 | { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int w1,w2,x1,x2,m; 11 | cin>>w1>>w2>>x1>>x2>>m; 12 | int difference = w2-w1; 13 | int minRange = x1 * m; 14 | int maxRange = x2 * m; 15 | if(difference >= minRange && difference <= maxRange) 16 | cout<<"1"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n,m; 7 | cin>>n>>m; 8 | int x[n],y[n]; 9 | for(int i=0;i>x[i]>>y[i]; 11 | int a[n],b[n],c[n],d[n]; 12 | for(int i=0;i>a[i]>>b[i]>>c[i]>>d[i]; 14 | for(int i=0;ic[i]) 17 | { 18 | swap(a[i],c[i]); 19 | swap(b[i],d[i]); 20 | } 21 | if(i%2==0) 22 | { 23 | cout<<-a[i]<<" "<<-b[i]-1< 2 | using namespace std; 3 | #define ll long long int 4 | int main() { 5 | 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | float k1,k2,k3,v; 11 | cin>>k1>>k2>>k3>>v; 12 | float t = (k1*k2*k3*v); 13 | float res = 100.00/t; 14 | float a=9.575; 15 | if(res=a) 18 | cout<<"NO"< 2 | using namespace std; 3 | #define int long long int 4 | #define endl "\n" 5 | #define m 1000000007 6 | int power(int x, unsigned int y, int p) 7 | { 8 | int res = 1; 9 | x = x % p; 10 | if (x == 0) return 0; 11 | while (y > 0) 12 | { 13 | if (y & 1) 14 | res = (res*x) % p; 15 | y = y>>1; // y = y/2 16 | x = (x*x) % p; 17 | } 18 | return res; 19 | } 20 | int32_t main() 21 | { 22 | int t;cin>>t; 23 | while(t--) 24 | { 25 | int n;cin>>n; 26 | cout< 2 | using namespace std; 3 | #define ll long long int 4 | #define loop(i,a,b) for(int i=a;i<(b);i++) 5 | #define ff first 6 | #define ss second 7 | #define vi vector 8 | 9 | 10 | int main() 11 | { 12 | ios_base::sync_with_stdio(false); 13 | cin.tie(NULL); 14 | cout.tie(NULL); 15 | string s; 16 | cin>>s; 17 | ll countZ=0,countO=0; 18 | for(int i=0;i 2 | #include 3 | 4 | using namespace std; 5 | 6 | long long int sum(int a,int b,int c,int d){ 7 | int r=a/b; 8 | int q=a%b; 9 | long long int s=((r*c)+(r*d*(r-1)/2))*b+(c+(r*d))*q; 10 | return s; 11 | } 12 | int main() { 13 | 14 | int t; 15 | std::cin>>t; 16 | while(t--){ 17 | int D,d,p,q; 18 | std::cin>>D>>d>>p>>q; 19 | std::cout< 2 | using namespace std; 3 | void visa(int a,int b,int c,int d, int e, int f){ 4 | string s="NO"; 5 | if(b>=a){ 6 | if(d>=c){ 7 | if(f<=e){ 8 | s="YES"; 9 | } 10 | } 11 | } 12 | std::cout<>t; 18 | while(t--){ 19 | int a,b,c,d,e,f; 20 | std::cin>>a>>b>>c>>d>>e>>f; 21 | visa(a,b,c,d,e,f); 22 | 23 | } 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Codechef/C++/coin_triangle_problem.cpp: -------------------------------------------------------------------------------- 1 | /* Coins And Triangle || Problem Code: TRICOIN */ 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int T; 8 | cin >> T; 9 | 10 | while(T--) 11 | { 12 | int n; 13 | cin >> n; 14 | 15 | int i = 1, sum = 0, count = 0; 16 | 17 | if(n == 1) 18 | { 19 | cout << 1 << endl; 20 | } 21 | 22 | else 23 | { 24 | while(sum <= n) 25 | { 26 | sum += i; 27 | i++; 28 | count++; 29 | } 30 | cout << (count-1) << endl; 31 | } 32 | 33 | } 34 | 35 | /* 36 | Input 37 | 3 38 | 3 5 7 39 | 40 | Output 41 | 2 42 | 2 43 | 3 44 | */ 45 | -------------------------------------------------------------------------------- /Codechef/C++/false_number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | /* take input of test cases */ 7 | cin>>t; 8 | 9 | /* loop while testcase !=0 */ 10 | while(t--){ 11 | string s; 12 | /* take string input */ 13 | cin>>s; 14 | 15 | /* if first digit is 1 */ 16 | if(s[0]=='1'){ 17 | s[0]='0'; 18 | cout<<1< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | string s; 11 | cin>>s; 12 | char ch; 13 | string st1="10"; 14 | ch = s.at(0); 15 | if(ch == '1') 16 | s.replace(0,1,st1); 17 | else 18 | s="1"+s; 19 | cout< 4 | using namespace std; 5 | 6 | int gcd(int n1, int n2) 7 | { 8 | if (n2 != 0) 9 | return gcd(n2, n1 % n2); 10 | else 11 | return n1; 12 | } 13 | int main() 14 | { 15 | int t; 16 | cin>>t; 17 | while(t--) 18 | { 19 | int x,y; 20 | cin>>x>>y; 21 | if(gcd(x,y)>1) 22 | cout<<"0"<1) 24 | cout<<"1"<1) 26 | cout<<"1"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | string s; 11 | cin>>s; 12 | char ch; 13 | bool flag=1; 14 | if(s.at(0) != '<' || s.at(1) != '/' || s.at(s.length()) != '>') 15 | { 16 | cout<<"Error"< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | int a[n]; 13 | for (int i = 0; i < n; i++) 14 | { 15 | cin>>a[i]; 16 | } 17 | map v; 18 | int c =0 ; 19 | for (int i = 0; i < n; i++) 20 | { 21 | if(v.find(a[i])==v.end()) 22 | { 23 | v[a[i]]++; 24 | c++; 25 | } 26 | else 27 | { 28 | if(v[a[i]] 2 | using namespace std; 3 | 4 | int main() { 5 | int t,k; 6 | cin>>t; // scanning number of testcases. 7 | while(t--) 8 | { 9 | cin>>k; //scanning inputs 10 | for(int i=1;i<=k;i++) 11 | { 12 | for(int j=0;j=k) 15 | cout<<"("; 16 | else 17 | cout<<" "; 18 | } 19 | cout<<"*"; 20 | for(int j=1;j<=i;j++) 21 | { 22 | cout<<")"; 23 | } 24 | cout< 5 | using namespace std; 6 | 7 | int main() { 8 | long long n,q; 9 | cin>>n>>q; 10 | vectorarr(n); 11 | for(int i=0;i>arr[i]; 14 | } 15 | while(q--) 16 | { 17 | long long num; 18 | cin>>num; 19 | if(num==1) 20 | { 21 | long long l,r,x; 22 | cin>>l>>r>>x; 23 | for(int i=l-1;i<=r-1;i++) 24 | { 25 | arr[i]=arr[i]+((x+i+1-l)*(x+i+1-l)); 26 | } 27 | } 28 | if(num==2) 29 | { 30 | long long y; 31 | cin>>y; 32 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int a,b,x; 11 | cin>>a>>b>>x; 12 | cout<<(b-a)/x< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int a[n],b[n],c[n],j=0,p=0; 12 | for(int i=0;i>a[i]; 15 | if(a[i]%2) 16 | b[j++]=a[i]; 17 | else 18 | c[p++]=a[i]; 19 | } 20 | p--; 21 | j--; 22 | for(int i=0;i=0) 25 | cout< 2 | 3 | int arr[1000000]; 4 | int main() 5 | { 6 | int i,j,t; 7 | 8 | scanf("%d",&t); 9 | for(i=0;i 0) 17 | { 18 | while(arr[i]--) 19 | printf("%d\n",i); 20 | } 21 | } 22 | return 0; 23 | } 24 | 25 | /* 26 | 27 | Example 28 | Input: 29 | 5 30 | 5 31 | 3 32 | 6 33 | 7 34 | 1 35 | Output: 36 | 1 37 | 3 38 | 5 39 | 6 40 | 7 41 | 42 | */ 43 | 44 | -------------------------------------------------------------------------------- /Codechef/C/cheflandvisa.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) { 4 | long long t;//Inputting the total testcases 5 | scanf("%lld",&t); 6 | while(t--!=0) 7 | { 8 | long long x1,x2,y1,y2,z1,z2; 9 | scanf("%lld %lld %lld %lld %lld %lld",&x1,&x2,&y1,&y2,&z1,&z2); 10 | if(x2>=x1 && y2>=y1 && z2<=z1)//Checking the condition 11 | printf("YES\n"); 12 | else 13 | printf("NO\n"); 14 | } 15 | return 0; 16 | } 17 | 18 | /* 19 | Input- 20 | 4 21 | 20 50 2100 1900 6 6 22 | 50 20 1900 1900 5 5 23 | 20 20 1900 1900 1 6 24 | 27 27 1920 1920 3 3 25 | Output- 26 | NO 27 | NO 28 | NO 29 | YES 30 | */ 31 | -------------------------------------------------------------------------------- /Codechef/Java/Bella_ciao.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | 5 | 6 | class bella 7 | { 8 | public static void main (String[] args) throws java.lang.Exception 9 | { 10 | Scanner sc=new Scanner(System.in); 11 | long t; 12 | t=sc.nextLong(); 13 | while(t--!=0) 14 | { 15 | long d,D,P,Q,sum=0; 16 | D=sc.nextLong(); 17 | d=sc.nextLong(); 18 | P=sc.nextLong(); 19 | Q=sc.nextLong(); 20 | long k=D/d; 21 | if(D%d==0) 22 | { 23 | sum+=d*(P*k+(k*(k-1)/2)*Q); 24 | } 25 | else 26 | { 27 | sum+=d*(P*k+(k*(k-1)/2)*Q); 28 | sum+=(D%d)*(P+(k*Q)); 29 | } 30 | System.out.println(sum); 31 | 32 | } 33 | 34 | } 35 | } 36 | 37 | /* 38 | Input- 39 | 3 40 | 2 1 1 1 41 | 3 2 1 1 42 | 5 2 1 2 43 | Output- 44 | 3 45 | 4 46 | 13 47 | */ 48 | -------------------------------------------------------------------------------- /Codechef/Java/Chess_Match.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class MyClass { 3 | public static void main(String args[]) { 4 | Scanner sc=new Scanner(System.in); 5 | int t=sc.nextInt(); 6 | for(int x=1;x<=t;x++) 7 | { 8 | int a=sc.nextInt(); 9 | int b=sc.nextInt(); 10 | int c=sc.nextInt(); 11 | int d=c+b; 12 | System.out.println((360+2*a)-d); 13 | } 14 | 15 | } 16 | } 17 | 18 | 19 | // Input 20 | // 3 21 | // 10 0 2 22 | // 11 2 1 23 | // 12 192 192 24 | // Output 25 | // 378 26 | // 379 27 | // 0 -------------------------------------------------------------------------------- /Codechef/Java/CoinsAndTriangle.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.Scanner; 3 | import java.lang.Math; 4 | 5 | public class CoinsAndTriangle { 6 | 7 | public static void main(String[] args) { 8 | Scanner cin = new Scanner(System.in); 9 | 10 | int t = cin.nextInt(); 11 | 12 | for (int i = 0; i < t; i++) { 13 | int n = cin.nextInt(); 14 | 15 | int ans = (int) ((Math.sqrt(1 + 8.0 * n)) - 1); 16 | ans = ans / 2; 17 | 18 | System.out.println(ans); 19 | } 20 | } 21 | } 22 | 23 | /* 24 | Example: 25 | Input 26 | 3 27 | 3 28 | 5 29 | 7 30 | 31 | Output 32 | 2 33 | 2 34 | 3 35 | */ -------------------------------------------------------------------------------- /Codechef/Java/CovidAnalyzer.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | 5 | /* Name of the class has to be "Main" only if the class is public. */ 6 | class CovidAnalyzer 7 | { 8 | public static void main (String[] args) throws java.lang.Exception 9 | { 10 | // your code goes here 11 | Scanner sc=new Scanner(System.in); 12 | int t=sc.nextInt(); 13 | long arr[]=new long[90]; 14 | arr[0]=1; 15 | arr[1]=2; 16 | for(int i=2;i<90;i++) 17 | { 18 | arr[i]=arr[i-1]+arr[i-2]; 19 | } 20 | for(int l=0;l 0){ 12 | int n = sc.nextInt(); 13 | int sum = 0; 14 | boolean flag = false; 15 | int[] a = new int[n]; 16 | for(int i = 0 ; i < n ; i++){ 17 | a[i] = sc.nextInt(); 18 | 19 | } 20 | Arrays.sort(a); 21 | for(int i = 0 ; i < n ; i++){ 22 | sum += Math.abs((i+1)-a[i]); 23 | if(a[i]>(i+1)) 24 | flag = true; 25 | } 26 | if((sum % 2 == 0)||(flag == true)) 27 | System.out.println("Second"); 28 | else 29 | System.out.println("First"); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Codechef/Java/Total Expenses.java: -------------------------------------------------------------------------------- 1 | /* package codechef; // don't place package name! */ 2 | 3 | import java.util.*; 4 | import java.lang.*; 5 | import java.io.*; 6 | 7 | /* Name of the class has to be "Main" only if the class is public. */ 8 | class Codechef 9 | { 10 | public static void main (String[] args) throws java.lang.Exception 11 | { 12 | Scanner sc = new Scanner(System.in); 13 | int test = sc.nextInt(); 14 | for (int t = 0 ; t < test ; t++){ 15 | int qty = sc.nextInt(); 16 | double price = sc.nextInt(); 17 | if (qty > 1000){ 18 | System.out.println(qty*price-0.1*qty*price); 19 | } 20 | else{ 21 | System.out.println(qty*price); 22 | } 23 | } 24 | } 25 | } 26 | 27 | /* Example Test Case 28 | Input 29 | 30 | 3 31 | 100 120 32 | 10 20 33 | 1200 20 34 | 35 | Output 36 | 37 | 12000.000000 38 | 200.000000 39 | 21600.000000 40 | */ 41 | -------------------------------------------------------------------------------- /Codechef/Java/Turbo Sort.java: -------------------------------------------------------------------------------- 1 | 2 | import java.util.*; 3 | import java.lang.*; 4 | import java.io.*; 5 | 6 | class Codechef 7 | { 8 | public static void main (String[] args) throws java.lang.Exception 9 | { 10 | Scanner sc = new Scanner(System.in); 11 | 12 | int testCases = sc.nextInt(); 13 | // we have taken the array of size testCases 14 | int[] arr = new int[testCases]; 15 | //this loop will iterate from 0 to length of the array 16 | //to take the user input as array index value 17 | for(int i = 0;i= x+0.5){ 19 | if(x%5 == 0){ 20 | amnt = amnt-x-0.5; 21 | } 22 | } 23 | System.out.println(amnt); 24 | } 25 | } 26 | 27 | // 28 | // Example test case 29 | // Input: 30 | // 42 120.00 31 | // 32 | // Output: 33 | // 120.00 34 | // 35 | // Input: 36 | // 300 120.00 37 | // 38 | // Output: 39 | // 120.00 40 | -------------------------------------------------------------------------------- /Codechef/Java/cheflandvisa.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | 5 | class Codechef 6 | { 7 | public static void main (String[] args) throws java.lang.Exception 8 | { 9 | Scanner sc=new Scanner(System.in); 10 | long t=sc.nextLong();//Inputting the total testcases 11 | while(t--!=0) 12 | { 13 | long x1,x2,y1,y2,z1,z2; 14 | x1=sc.nextLong(); 15 | x2=sc.nextLong(); 16 | y1=sc.nextLong(); 17 | y2=sc.nextLong(); 18 | z1=sc.nextLong(); 19 | z2=sc.nextLong(); 20 | if(x2>=x1 && y2>=y1 && z2<=z1)//Checking the condition 21 | System.out.println("YES"); 22 | else 23 | System.out.println("NO"); 24 | } 25 | 26 | } 27 | } 28 | 29 | /* 30 | Input- 31 | 4 32 | 20 50 2100 1900 6 6 33 | 50 20 1900 1900 5 5 34 | 20 20 1900 1900 1 6 35 | 27 27 1920 1920 3 3 36 | Output- 37 | NO 38 | NO 39 | NO 40 | YES 41 | */ 42 | -------------------------------------------------------------------------------- /Codechef/Java/summer_heat.java: -------------------------------------------------------------------------------- 1 | /*Summer Heat solution , codechef june long challenge Problem Code: COCONUT*/ 2 | 3 | import java.util.*; 4 | import java.lang.*; 5 | import java.io.*; 6 | 7 | class summerheat 8 | { 9 | public static void main (String[] args) throws java.lang.Exception 10 | { 11 | Scanner in = new Scanner(System.in); 12 | int t = in.nextInt(); 13 | 14 | int arr[] = new int[t]; 15 | 16 | for(int i=0; i0) 10 | { 11 | int n = sc.nextInt(); 12 | int arr[] = new int[n]; 13 | arr[0]=sc.nextInt(); 14 | int min = arr[0]; 15 | for(int i =1;i= x1 and y2 >= y1 and z2 <= z1, if all this conditions statisfies then print "YES" else "NO" 3 | # In the given solution: 4 | # x1 = n[0] 5 | # x2 = n[1] 6 | # y1 = n[2] 7 | # y2 = n[3] 8 | # z1 = n[4] 9 | # z2 = n[5] 10 | 11 | t = int(input()) # Taking input for number of test cases 12 | for i in range(t): 13 | temp = input() 14 | n = temp.split(" ") # Spliting the string temp based on spaces to get individual element 15 | if ((n[1] >= n[0]) and (n[3] >= n[2]) and (n[5] <= n[4])): 16 | print("YES") 17 | else: 18 | print("NO") 19 | 20 | # Sample input/output 21 | 22 | # Example Input 23 | # 4 24 | # 20 50 2100 1900 6 6 25 | # 50 20 1900 1900 5 5 26 | # 20 20 1900 1900 1 6 27 | # 27 27 1920 1920 3 3 28 | 29 | # Example Output 30 | # NO 31 | # NO 32 | # NO 33 | # YES -------------------------------------------------------------------------------- /Codechef/Python/Coins And Triangle (TRICOIN).py: -------------------------------------------------------------------------------- 1 | import math 2 | t = int(input()) #taking input of test cases 3 | for i in range(t): 4 | s = int(input()) #s denotes number of gold coin 5 | d= (1+8*s) 6 | d= int (math.sqrt(d)) 7 | n = int((-1+d)/2) 8 | print(n) 9 | #this is a simple AP(Arithmatic Progression) problem 10 | # we used the sum of AP formula S = n/2(2a+ (n-1)diff) 11 | # here a = first term(1 in this case), diff= common difference(1 in this case), n=number of terms(to be found),s = sum(total coins) 12 | #solving the above eqaution we get n^2+n-2s=0 13 | #to find the root of the above eq we used n = (-b+sqrt(b^2-4ac))/2a, output n 14 | 15 | # Sample input/output 16 | 17 | # Input 18 | # 3 19 | # 3 20 | # 5 21 | # 7 22 | 23 | # Output 24 | # 2 25 | # 2 26 | # 3 27 | -------------------------------------------------------------------------------- /Codechef/Python/ICPC_BALLOON.py: -------------------------------------------------------------------------------- 1 | #Solution to the ICPC Balloon Problem 2 | #Taking Testcases 3 | for t in range(int(input())): 4 | #Input Code N & Array 5 | N = int(input()) 6 | A = list(map(int, input().split())) 7 | 8 | 9 | #Actual Problem's Solution Begun 10 | i = 0 11 | s = set() 12 | while i < N: 13 | if A[i] <= 7: 14 | s.add(A[i]) 15 | if len(s) == 7: 16 | break 17 | i+=1 18 | print(i+1) if i=h: 6 | print("YES") 7 | else: 8 | print("NO") 9 | -------------------------------------------------------------------------------- /Codechef/Python/Nobel.py: -------------------------------------------------------------------------------- 1 | #Problem Link: https://www.codechef.com/START2C/problems/NOBEL 2 | 3 | t = int(input()) 4 | for i in range(t): 5 | n, m = map(int, input().split()) 6 | li = list(map(int, input().split())) 7 | f = 0 8 | s = set(li) 9 | if len(s)==m: 10 | print("No") 11 | else: 12 | print("Yes") 13 | -------------------------------------------------------------------------------- /Codechef/Python/Possible Victory.py: -------------------------------------------------------------------------------- 1 | #Problem Link: https://www.codechef.com/START2C/problems/T20MCH 2 | r, o, c = map(int, input().split()) 3 | if c+36*(20-o)>r: 4 | print("YES") 5 | else: 6 | print("NO") -------------------------------------------------------------------------------- /Codechef/Python/Small Factorials.py: -------------------------------------------------------------------------------- 1 | def fact(n): 2 | if (n == 1): 3 | return n; 4 | else: 5 | return n*fact(n-1); 6 | 7 | 8 | test = int(input()) 9 | for i in range (0,test): 10 | val = int(input()) 11 | print(fact(val)) 12 | 13 | 14 | ##Example Test Case 15 | # Sample input: 16 | # 4 17 | # 1 18 | # 2 19 | # 5 20 | # 3 21 | # Sample output: 22 | # 23 | # 1 24 | # 2 25 | # 120 26 | # 6 27 | -------------------------------------------------------------------------------- /Codechef/Python/Team Name.py: -------------------------------------------------------------------------------- 1 | # Problem Link: https://www.codechef.com/FEB21C/problems/TEAMNAME 2 | 3 | t = int(input()) 4 | for i in range(t): 5 | n = int(input()) 6 | li = list(input().split()) 7 | di = {} 8 | for i in li: 9 | temp = i[1:] 10 | if temp in di: 11 | di[temp].append(i[0]) 12 | else: 13 | di[temp] = [i[0]] 14 | di1 = list(di.keys()) 15 | sumi = 0 16 | for i in range(len(di)): 17 | for j in range(i+1, len(di)): 18 | kl1 = di[di1[i]] 19 | kl2 = di[di1[j]] 20 | temp = len(set(kl1+kl2)) 21 | sumi+=(temp-len(di[di1[i]]))*(temp-len(di[di1[j]])) 22 | print(2*sumi) 23 | 24 | -------------------------------------------------------------------------------- /Codechef/Python/Tsort.py: -------------------------------------------------------------------------------- 1 | vin = int(input()) 2 | suy = [] 3 | for i in range(vin): 4 | suy.append(int(input())) 5 | suy.sort(reverse=False) 6 | for nums in suy: 7 | print(nums) 8 | -------------------------------------------------------------------------------- /Codechef/Python/gold_coin.py: -------------------------------------------------------------------------------- 1 | #Bytelandian gold coins Problem Code: COINS codechef 2 | result=dict() 3 | def maxdollars(n): 4 | if(n>=0 and n<=11): 5 | result[n]=n 6 | return result[n] 7 | if n in result: 8 | return result[n] 9 | ans=maxdollars(n//2)+maxdollars(n//3)+maxdollars(n//4) 10 | if(ans>n): 11 | result[n]=ans 12 | else: 13 | result[n]=n 14 | return(result[n]) 15 | while(1): 16 | try: 17 | n=int(input()) 18 | res=maxdollars(n) 19 | print(res) 20 | except: 21 | break 22 | #Example 23 | # input:-12 24 | #output:-13 -------------------------------------------------------------------------------- /Codechef/Python/hollow butterfly pattern.py: -------------------------------------------------------------------------------- 1 | row = int(input("Enter number of rows (even): ")) 2 | 3 | n = row//2 4 | 5 | print("Generated butterfly pattern is:\n") 6 | # Upper part 7 | for i in range(1,n+1): 8 | for j in range(1, 2*n+1): 9 | if j>i and j< 2*n+1-i: 10 | print(" ", end="") 11 | else: 12 | print("* ", end="") 13 | print() 14 | 15 | # Lower part 16 | for i in range(n,0,-1): 17 | for j in range(2*n,0,-1): 18 | if j>i and j< 2*n+1-i: 19 | print(" ", end="") 20 | else: 21 | print("* ", end="") 22 | print() 23 | -------------------------------------------------------------------------------- /Codechef/Python/pattern_codechef.py: -------------------------------------------------------------------------------- 1 | for i in range(int(input())): 2 | k=int(input()) 3 | for i in range(k): 4 | print((" ")*(k-i-1),end="") 5 | print((i+1)*"(",end="") 6 | print("*",end="") 7 | print((i+1)*")",end="") 8 | print() 9 | -------------------------------------------------------------------------------- /Codechef/Python/smartphone.py: -------------------------------------------------------------------------------- 1 | num = int(input()) 2 | suy = [] 3 | 4 | for i in range(num): 5 | suy.append(int(input())) 6 | 7 | suy.sort() 8 | 9 | for i in range(num): 10 | suy[i] = suy[i]*(num-i) 11 | 12 | print(max(suy)) 13 | -------------------------------------------------------------------------------- /Codeforces/C++/D. Same Differences.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | // Question link : https://codeforces.com/contest/1520/problem/D 5 | 6 | #define int long long 7 | #define vi vector 8 | #define vvi vector> 9 | #define pb push_back 10 | #define MAX 9223372036854775807 11 | #define fucking ios_base::sync_with_stdio(false) 12 | #define fastIO cin.tie(0) 13 | 14 | void solution() 15 | { 16 | //code here 17 | int n; 18 | cin >> n; 19 | map a; 20 | long long res = 0; 21 | for (int i = 0; i < n; i++) 22 | { 23 | int x; 24 | cin >> x; 25 | x -= i; 26 | res += a[x]; 27 | a[x]++; 28 | } 29 | cout << res << endl; 30 | } 31 | 32 | signed main() 33 | { 34 | fucking; 35 | fastIO; 36 | int t = 1; 37 | cin >> t; 38 | while (t--) 39 | solution(); 40 | } 41 | -------------------------------------------------------------------------------- /Codeforces/C++/Mountain_Scenery.cpp: -------------------------------------------------------------------------------- 1 | // question link: https://codeforces.com/contest/218/problem/A 2 | #include 3 | using namespace std; 4 | int arr[105]; 5 | 6 | int main() { 7 | int n,k; 8 | cin>>n>>k; 9 | int max=0; 10 | int nodes=(n*2)+1; 11 | for(int i=0;i>arr[i]; 13 | if(arr[i]>max) 14 | max=arr[i]; 15 | } 16 | 17 | for(int i=0;iarr[i-1]&&(arr[i]-1)>arr[i+1]){ 20 | arr[i]-=1; 21 | --k; 22 | } 23 | } 24 | 25 | for(int i=0;i 2 | #include 3 | #include 4 | using namespace std; 5 | using namespace __gnu_pbds; 6 | 7 | typedef tree,null_type,less,rb_tree_tag; 8 | tree_order_statistics_node_update> 9 | PBDS; 10 | int main() 11 | { 12 | 13 | int n; 14 | cin>>n; 15 | int a[n],b[n],c[n]; 16 | for(int i=0;i>a[n]; 18 | for(int i=0;i>b[n]; 20 | for(int i=0;i 2 | #define endl '\n' 3 | #define ll long long int 4 | using namespace std; 5 | 6 | bool kmain(double a) 7 | { 8 | ll p = sqrt(a); 9 | 10 | if(p*p==a) 11 | { 12 | return true; 13 | } 14 | else 15 | { 16 | return false; 17 | } 18 | } 19 | 20 | int main() 21 | { 22 | int t; 23 | cin>>t; //testcases 24 | while(t--) 25 | { 26 | ll n; 27 | cin>>n; //number of puzzel pieces 28 | if(n%2!=0) 29 | { 30 | cout<<"NO"< 2 | #include 3 | 4 | using namespace std; 5 | int main(){ 6 | int arr[5][5],b,c; 7 | for( int i=0;i<5;i++){ 8 | for( int j=0;j<5;j++){ 9 | std::cin>>arr[i][j]; 10 | if(arr[i][j]==1){ 11 | b=i; 12 | c=j; 13 | } 14 | } 15 | } 16 | int count = abs(b-2)+abs(c-2); 17 | std::cout< 3 | using namespace std; 4 | int main(){ 5 | int n,x,a,b; 6 | bool p(true); 7 | cin>>n>>x; 8 | while(n--){ 9 | cin>>a>>b; 10 | if(x==a||x==b||x==7-a||x==7-b) p = false; 11 | x = 7-x; 12 | }cout<<(p?"YES":"NO"); 13 | return 0; 14 | } 15 | 16 | // Test Case 1 17 | // i/p 18 | // 3 19 | // 6 20 | // 3 2 21 | // 5 4 22 | // 2 4 23 | // o/p 24 | // YES 25 | 26 | // Test Case 2 27 | // i/p 28 | // 3 29 | // 3 30 | // 2 6 31 | // 4 1 32 | // 5 3 33 | // o/p 34 | // NO -------------------------------------------------------------------------------- /Codeforces/C++/evenodd.cpp: -------------------------------------------------------------------------------- 1 | //codeforces solution 319/A 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main() { 7 | long long int n,k,t; 8 | cin>>n>>k; 9 | if(n%2==0){ 10 | t=n/2;} 11 | else{ 12 | t=n/2+1; 13 | } 14 | if(k<=t){ 15 | cout<<(2*k)-1<t){ 18 | cout<<2*(k-t)< 2 | #include 3 | using namespace std; 4 | int main(){ 5 | string s = "abcdefghijklmnopqrstuvwxyz"; 6 | int n,k; 7 | cin>>n>>k; 8 | string s1=""; 9 | for(int i=0;i 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin>>n; 7 | int a[n]; 8 | int i,j,sum=0,c=0; 9 | for(j=0;j>a[i]; 11 | sort(a,a+n); //sorting the array in ascending order 12 | for(i=0;i 7 | #include 8 | using namespace std; 9 | 10 | int main() 11 | { 12 | int n; 13 | cin>>n; 14 | if(n%2==0 && n>2){ 15 | cout<<"YES"; 16 | } 17 | else{ 18 | cout<<"NO"; 19 | } 20 | return 0; 21 | 22 | } -------------------------------------------------------------------------------- /Codeforces/C++/way_to_long_word.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t; 8 | cin>>t; 9 | while(t--){ 10 | string s; 11 | string sn; 12 | cin>>s; 13 | if(s.length()>10){ 14 | int count=s.length()-2; 15 | cout< 9 | 10 | int main() 11 | { 12 | int t; 13 | scanf(%d,&t); 14 | 15 | while(t--){ 16 | 17 | int n; 18 | cin >> n; 19 | if(n % 2 == 1){ 20 | printf("Bob\n"); 21 | continue; 22 | } 23 | int cnt = 0; 24 | while(n % 2 == 0){ 25 | cnt++; 26 | n /= 2; 27 | } 28 | 29 | if(n > 1){ 30 | printf("Alice\n"); 31 | }else if(cnt % 2 == 0){ 32 | printf("Alice\n"); 33 | }else printf("Bob\n"); 34 | } 35 | } 36 | 37 | /* TestCases 38 | 39 | Input: 1 40 | Output Bob 41 | 42 | Input: 4 43 | Output Alice 44 | 45 | Input 12 46 | Output Alice 47 | 48 | Input 69 49 | Output Bob 50 | 51 | */ 52 | -------------------------------------------------------------------------------- /Codeforces/C/Watermelon.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main () 3 | { 4 | int w; 5 | scanf("%d",&w); // number of watermelons 6 | if(w%2==0 && w!=2) 7 | { 8 | printf("YES"); 9 | } 10 | else 11 | { 12 | printf("NO"); 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Codeforces/C/Way Too Long Words.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int t; 7 | scanf("%d",&t); //total words 8 | 9 | while(t--) 10 | { 11 | char word[101]; 12 | scanf("%s",word); //input words 13 | 14 | int len = strlen(word); 15 | if(len>10) 16 | { 17 | printf("%c%d%c\n",word[0],len-2,word[len-1]); 18 | } 19 | else 20 | { 21 | printf("%s\n",word); 22 | } 23 | 24 | } 25 | 26 | 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Codeforces/C/petya_and_strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main () 4 | { 5 | char strone[100]; 6 | char strtwo[100]; 7 | 8 | scanf("%s",strone); 9 | scanf("%s",strtwo); 10 | for ( int i = 0; strone[i]!='\0'; i++) { 11 | if(strone[i] >= 'a' && strone[i] <= 'z') { 12 | strone[i] = strone[i] -32; 13 | } 14 | } 15 | for ( int i = 0; strtwo[i]!='\0'; i++) { 16 | if(strtwo[i] >= 'a' && strtwo[i] <= 'z') { 17 | strtwo[i] = strtwo[i] -32; 18 | } 19 | } 20 | if ( strcmp(strone,strtwo) == 0 ) { 21 | printf("%d",0); 22 | } 23 | else if ( strcmp(strone,strtwo) > 0 ) { 24 | printf("%d",1); 25 | } 26 | else { 27 | printf("%d",-1); 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /Codeforces/Java/DiceTower.java: -------------------------------------------------------------------------------- 1 | //Question link: https://codeforces.com/contest/225/problem/A 2 | import java.util.*; 3 | public class DiceTower{ 4 | public static void main(String[] args){ 5 | Scanner s = new Scanner(System.in); 6 | int n = s.nextInt(); 7 | int x = s.nextInt(); 8 | int a = s.nextInt(); 9 | int b = s.nextInt(); 10 | boolean flag = false; 11 | for (int i = 1; i < n; i++){ 12 | int c = s.nextInt(); 13 | int d = s.nextInt(); 14 | if (c == x || d == x || c == 7-x || d == 7-x){ 15 | flag = true; 16 | break; 17 | } 18 | } 19 | if (flag) System.out.println("NO"); 20 | else System.out.println("YES"); 21 | } 22 | } 23 | 24 | /* Test Cases: 25 | Input: 26 | 3 27 | 6 28 | 3 2 29 | 5 4 30 | 2 4 31 | Output: 32 | YES 33 | 34 | Input: 35 | 3 36 | 3 37 | 2 6 38 | 4 1 39 | 5 3 40 | Output: 41 | NO 42 | */ 43 | 44 | -------------------------------------------------------------------------------- /Codeforces/Java/False Numbers.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | class MyClass { 3 | public static void main(String args[]) { 4 | Scanner sc=new Scanner(System.in); 5 | int t=sc.nextInt(); 6 | for(int x=1;x<=t;x++) 7 | { 8 | String c=""; 9 | String s=sc.next(); 10 | if(s.charAt(0)=='1') 11 | { 12 | c=s.charAt(0)+"0"+s.substring(1); 13 | } 14 | else 15 | { 16 | c="1"+s.substring(0); 17 | } 18 | System.out.println(c); 19 | 20 | } 21 | 22 | } 23 | } 24 | 25 | // Input 26 | // 2 27 | // 9876543211 28 | // 12345678999 29 | // Output 30 | // 19876543211 31 | // 102345678999 -------------------------------------------------------------------------------- /Codeforces/Java/Twins.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | public class Twins{ 3 | public static void main(String []args){ 4 | Scanner sc=new Scanner(System.in); 5 | int n=sc.nextInt(); 6 | long sum=0; //sum of the coins 7 | int mincoins=0; 8 | long mincoinssum=0; 9 | int coins[]=new int[n]; //these are indivisual coins 10 | for(int i=0;i=0;j--){ 16 | mincoinssum=mincoinssum+coins[j]; 17 | if(mincoinssum>(sum-mincoinssum)){ 18 | mincoins++; 19 | break; 20 | } 21 | mincoins++; 22 | } 23 | System.out.println(mincoins); 24 | } 25 | } 26 | /* Input: 27 | 3 28 | 2 1 2 29 | Output: 2 30 | */ -------------------------------------------------------------------------------- /Codeforces/Java/taxi.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.lang.*; 3 | import java.io.*; 4 | 5 | /* Name of the class has to be "Main" only if the class is public. */ 6 | class taxi 7 | { 8 | public static void main (String[] args) throws java.lang.Exception 9 | { 10 | Scanner sc=new Scanner(System.in); 11 | int n; 12 | int count[]=new int[5]; 13 | n=sc.nextInt(); 14 | while (n--!=0) 15 | { 16 | int s=sc.nextInt(); 17 | count[s] += 1; 18 | } 19 | int total = count[4] + count[3] + count[2] / 2; 20 | count[1] -= count[3]; 21 | if (count[2] % 2 == 1) 22 | { 23 | total += 1; 24 | count[1] -= 2; 25 | } 26 | if (count[1] > 0) 27 | { 28 | total += (count[1] + 3) / 4; 29 | } 30 | System.out.println(total); 31 | } 32 | } 33 | 34 | /* 35 | input- 36 | 5 37 | 1 2 4 3 3 38 | Output- 39 | 4 40 | */ 41 | -------------------------------------------------------------------------------- /Codeforces/Python/Deleting_divisors.py: -------------------------------------------------------------------------------- 1 | #Deleting Divisors 2 | for _ in range(int(input())): 3 | n = int(input()) 4 | cnt = 0 5 | if n%2==1: 6 | print("Bob") 7 | continue 8 | while n%2==0: 9 | cnt+=1 10 | n//=2 11 | if n>1 or cnt%2==0: 12 | print("Alice") 13 | else: 14 | print("Bob") 15 | 16 | 17 | #Example:- 18 | #input 19 | # 4 20 | #1 21 | #4 22 | #12 23 | #69 24 | 25 | #output 26 | # Bob 27 | # Alice 28 | # Alice 29 | #;Bob 30 | 31 | -------------------------------------------------------------------------------- /Codeforces/Python/Indian Coin Change.py: -------------------------------------------------------------------------------- 1 | denominations = [1, 2, 5, 10, 20, 50, 100, 500, 1000] #denominations of indian currency 2 | n=len(denominations) 3 | 4 | def Coin_Change(V): 5 | 6 | change = [] # to store the change currencies 7 | 8 | for deno in range(n-1 , -1, -1): #reverse for loop 9 | 10 | while (V >= denominations[deno]): 11 | V -= denominations[deno] 12 | change.append(denominations[deno]) 13 | 14 | print("Minimal no. of coins needed:", len(change)) 15 | print("Changed currency: ", end=" ") 16 | for i in change: 17 | print(i, end=" ") 18 | 19 | 20 | # Driver Code 21 | V= int(input("Enter the amount: ")) 22 | Coin_Change(V) 23 | 24 | 25 | # Sample 26 | 27 | # Enter the amount: 72 28 | # Minimal no. of coins needed: 3 29 | # Changed currency: 50 20 2 -------------------------------------------------------------------------------- /Codeforces/Python/Way_too_long_words.py: -------------------------------------------------------------------------------- 1 | # python3 file 2 | 3 | n = int(input()) # taking number of test cases as input 4 | for i in range(n): 5 | w = input() # taking a word as input 6 | if(len(w) <= 10): # if length of the word is less than or equal to 10 7 | print(w) # we print that word directly 8 | else: 9 | # extracting first character and last character with length of string in between 10 | new_word = w[0]+str(len(w)-2)+w[len(w)-1] 11 | print(new_word) # printing new word 12 | -------------------------------------------------------------------------------- /Codeforces/Round 745/cqxymcountpermutations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | typedef long long int ll; 4 | int main() 5 | { 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | ll ans=1; 13 | ll mod=1e9+7; 14 | 15 | for(int i=2*n;i>=3;i--){ 16 | ans=(ans*i)%mod; 17 | } 18 | ans=ans%mod; 19 | 20 | cout< 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | /* 8 | * 9 | * Prosen Ghosh 10 | * American International University - Bangladesh (AIUB) 11 | * 12 | */ 13 | int main() { 14 | 15 | int T,ar[1000]; 16 | cin >> T; 17 | for(int i = 0;i < T; i++)cin >> ar[i]; 18 | for(int i = T-1; i >=0; i--)cout << ar[i] << " "; 19 | return 0; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /Data Structures/Array/C++/intersection of two sorted arrays.cpp: -------------------------------------------------------------------------------- 1 | //Program to find the intersection of two sorted arrays 2 | #include 3 | using namespace std; 4 | 5 | int printIntersection(int a1[], int a2[], int m, int n) 6 | { 7 | int i = 0; 8 | int j = 0; 9 | while (i < m && j < n) 10 | 11 | { 12 | if (a1[i] < a2[j]) 13 | i++; 14 | else if (a1[i] > a2[j]) 15 | j++; 16 | else 17 | { 18 | cout << a2[j++] << endl; 19 | i++; 20 | } 21 | } 22 | } 23 | 24 | int main() 25 | { 26 | int a1[] = {1, 2, 4, 5, 6}; 27 | int a2[] = {2, 3, 5, 7}; 28 | 29 | int m = sizeof(a1) / sizeof(a1[0]); 30 | int n = sizeof(a2) / sizeof(a2[0]); 31 | 32 | printIntersection(a1, a2, m, n); 33 | } 34 | //Output: 2 5 35 | -------------------------------------------------------------------------------- /Data Structures/Array/Python/2D Array.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | # Complete the hourglassSum function below. 8 | def hourglassSum(arr): 9 | maxsum = -99 10 | 11 | for i in range(4): 12 | for j in range(4): 13 | top = sum(arr[i][j:j+3]) 14 | mid = arr[i+1][j+1] 15 | bot = sum(arr[i+2][j:j+3]) 16 | 17 | hourglass = top+mid+bot 18 | 19 | maxsum = max(hourglass,maxsum) 20 | return maxsum 21 | 22 | if __name__ == '__main__': 23 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 24 | 25 | arr = [] 26 | 27 | for _ in range(6): 28 | arr.append(list(map(int, input().rstrip().split()))) 29 | 30 | result = hourglassSum(arr) 31 | 32 | fptr.write(str(result) + '\n') 33 | 34 | fptr.close() 35 | -------------------------------------------------------------------------------- /Data Structures/Array/Python/AdjacentDifferenceAlgo.py: -------------------------------------------------------------------------------- 1 | # Python code to demonstrate 2 | # to calculate difference 3 | # between adjacent elements in list 4 | 5 | # Size of List 6 | n = int(input("Enter the size of List : ")) 7 | 8 | # initialising empty list 9 | ini_list = [] 10 | 11 | # Taking n elements input in list 12 | for i in range(0,n): 13 | ini_list.append(int(input())) 14 | 15 | # printing ini_list 16 | print("intial_list", str(ini_list)) 17 | 18 | # Calculating difference list 19 | diff_list = [] 20 | for x, y in zip(ini_list[0::], ini_list[1::]): 21 | diff_list.append(y-x) 22 | 23 | # printing difference list 24 | print ("difference list: ", str(diff_list)) 25 | -------------------------------------------------------------------------------- /Data Structures/Array/Python/Intersection of two sorted array.py: -------------------------------------------------------------------------------- 1 | A=input() 2 | B=input() 3 | for i in A: 4 | if(i in B): 5 | print(i) # Take Input as list form 6 | -------------------------------------------------------------------------------- /Data Structures/Array/Python/ReverseArray.py: -------------------------------------------------------------------------------- 1 | arr = [] 2 | arr=[int(x) for x in input().split()] 3 | print("Original array: ") 4 | for i in range(0, len(arr)): 5 | print(arr[i]), 6 | print("Array in reverse order: ") 7 | #Loop through the array in reverse order 8 | for i in range(len(arr)-1, -1, -1): 9 | print(arr[i]), 10 | -------------------------------------------------------------------------------- /Data Structures/Array/Python/Union of two sorted array.py: -------------------------------------------------------------------------------- 1 | a=list(map(int,input('Enter elements of first list:').split())) 2 | b=list(map(int,input('Enter elements of second list:').split())) 3 | 4 | A=list(set(a)|set(b)) 5 | B=list(set(a)&set(b)) 6 | 7 | print('Union of the arrays:',A) 8 | 9 | 10 | #Input given a= 1 2 3 4 and b = 2 3 4 5 output:- union = 1 2 3 4 5 11 | -------------------------------------------------------------------------------- /Data Structures/Array/Python/searching largest and smallest in array.py: -------------------------------------------------------------------------------- 1 | def find_Small_Large(array): 2 | length = len(array) 3 | array.sort() 4 | print("Largest element is:", array[length-1]) 5 | print("Smallest element is:", array[0]) 6 | 7 | 8 | array=[10,35,39,40,56,69,77,79,82,92] 9 | Largest = find_Small_Large(array) 10 | 11 | #output should be 12 | # Largest element is: 92 13 | # smallest element is: 10 -------------------------------------------------------------------------------- /Data Structures/Tree/C++/Red Black Tree (Insertion and Deletion operation).cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ayush7614/Daily-Coding-DS-ALGO-Practice/c2af2a30eb156036bb0ba5f5e8f12094b96051fa/Data Structures/Tree/C++/Red Black Tree (Insertion and Deletion operation).cpp -------------------------------------------------------------------------------- /Data Structures/Tree/Java/InOrderTraversal.java: -------------------------------------------------------------------------------- 1 | package Tree.TreeTraversal; 2 | 3 | /** 4 | * Recursive Binary Tree InOder Traversal Code 5 | */ 6 | 7 | class InOrderTraversal { 8 | 9 | private class TreeNode { 10 | int data; 11 | TreeNode left, right; 12 | TreeNode(int item) { 13 | data = item; 14 | left = right = null; 15 | } 16 | } 17 | 18 | void printInOrder(TreeNode node) //Pass the root node 19 | { 20 | if(node==null) 21 | return; 22 | 23 | printInOrder(node.left); //Recursively call for left subtree 24 | System.out.println(node.data+" "); 25 | printInOrder(node.right); //Recursively call for right subtree 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Data Structures/Tree/Java/PostOrderTraversal.java: -------------------------------------------------------------------------------- 1 | package Tree.TreeTraversal; 2 | 3 | /** 4 | * Recursive Binary Tree PostOder Traversal Code 5 | */ 6 | 7 | public class PostOrderTraversal { 8 | 9 | private class TreeNode { 10 | int data; 11 | TreeNode left, right; 12 | TreeNode(int item) { 13 | data = item; 14 | left = right = null; 15 | } 16 | } 17 | 18 | void printPostOrder(TreeNode node) //pass root node here 19 | { 20 | if(node==null) 21 | return; 22 | 23 | printPostOrder(node.left); //Recursively call for left subtree 24 | printPostOrder(node.right); //Recursively call for right subtree 25 | System.out.println(node.data+" "); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /Data Structures/Tree/Java/PreOrderTraversal.java: -------------------------------------------------------------------------------- 1 | package Tree.TreeTraversal; 2 | 3 | /** 4 | * Recursive Binary Tree PreOder Traversal Code 5 | */ 6 | 7 | 8 | class PreOrderTraversal { 9 | 10 | private class TreeNode { 11 | int data; 12 | TreeNode left, right; 13 | TreeNode(int item) { 14 | data = item; 15 | left = right = null; 16 | } 17 | } 18 | 19 | void printPreOrder(TreeNode node) //pass root node here 20 | { 21 | if(node==null) 22 | return; 23 | 24 | System.out.println(node.data+" "); 25 | printPreOrder(node.left); //Recursively call for left subtree 26 | printPreOrder(node.right); //Recursively call for right subtree 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Data Structures/copyset.java: -------------------------------------------------------------------------------- 1 | package copyset; 2 | 3 | public class copysetbits { 4 | // let us start 5 | public static void main(String[] args) { 6 | // TODO Auto-generated method stub 7 | System.out.println(copybits(13, 10, 2, 3)); 8 | 9 | } 10 | // a -> b copy set bits in range 11 | public static int copybits(int a, int b, int l, int r) { 12 | //defining m1 13 | int m1 = 1; 14 | 15 | m1 = m1 << (r - l + 1); 16 | //You have to set bits in B which are set in A lying in the above mentioned range. 17 | m1 = m1 - 1; 18 | m1 = m1 << (l - 1); 19 | 20 | //Printing the updated number p. 21 | int actualmask = a & m1; 22 | return b | actualmask; 23 | 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Gfg/C++/Coin Change.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | 5 | ll possibleWays(ll coins[],ll n,ll val){ 6 | ll dp[n][val+1],i,j; 7 | memset(dp,0,sizeof(dp)); 8 | for(i=0;i<=val;i+=coins[0]) 9 | dp[0][i]=1; 10 | for(j=0;j>t; 24 | while(t--){ 25 | ll n,val,i; 26 | cin>>n; 27 | ll coins[n]; 28 | for(i=0;i>coins[i]; 30 | cin>>val; 31 | cout<left), height(node->right)); 20 | } 21 | -------------------------------------------------------------------------------- /Gfg/C++/Kadane's Algorithm.cpp: -------------------------------------------------------------------------------- 1 | using namespace std; 2 | 3 | int kadane(int *arr,int n){ 4 | 5 | int max_global,max_current; 6 | max_global=max_current=arr[0]; 7 | 8 | for(int i=1; imax_global){ 13 | max_global = max_current; 14 | } 15 | } 16 | return max_global; 17 | 18 | } 19 | 20 | int main() { 21 | //code 22 | int t; 23 | cin>>t; 24 | while(t--){ 25 | int n; 26 | cin>>n; 27 | int arr[n]; 28 | for(int i=0; i>arr[i]; 30 | } 31 | 32 | cout< 2 | using namespace std; 3 | int lastIndex(int a[], int g, int x) { 4 | if (g == 0) { 5 | return -1; 6 | } 7 | int ans = lastIndex(a + 1, g - 1, x); 8 | if (ans == -1) { 9 | if (a[0] == x) { 10 | return 0; 11 | } else { 12 | return -1; 13 | } 14 | } 15 | 16 | return ans + 1; 17 | } 18 | 19 | int main() { 20 | int n, x, a[200]; 21 | cin >> n; 22 | for (int i = 0; i < n; i++) { 23 | cin >> a[i]; 24 | } 25 | cin >> x; 26 | cout << lastIndex(a, n, x); 27 | } 28 | 29 | /*Example 30 | Input: 31 | 5 32 | 5 6 7 5 2 33 | 5 34 | Output: 35 | 3 36 | */ 37 | 38 | 39 | -------------------------------------------------------------------------------- /Gfg/C++/Level order traversal.cpp: -------------------------------------------------------------------------------- 1 | /* A binary tree Node 2 | struct Node 3 | { 4 | int data; 5 | struct Node* left; 6 | struct Node* right; 7 | 8 | Node(int x){ 9 | data = x; 10 | left = right = NULL; 11 | } 12 | }; 13 | */ 14 | //You are required to complete this method 15 | #include 16 | void levelOrder(Node* node) 17 | { 18 | //Your code here 19 | queueq; 20 | if(node == NULL) 21 | return; 22 | q.push(node); 23 | while(!q.empty()) 24 | { 25 | Node* t = q.front(); 26 | q.pop(); 27 | cout << t->data <<" "; 28 | if(t->left != NULL) 29 | q.push(t->left); 30 | if(t->right != NULL) 31 | q.push(t->right); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Gfg/C++/Maximum of all subarrays of size k.cpp: -------------------------------------------------------------------------------- 1 | // C++ Program to find the maximum for 2 | // each and every contiguous subarray of size k. 3 | #include 4 | using namespace std; 5 | 6 | // Method to find the maximum for each 7 | // and every contiguous subarray of size k. 8 | void printKMax(int arr[], int n, int k) 9 | { 10 | int j, max; 11 | 12 | for (int i = 0; i <= n - k; i++) 13 | { 14 | max = arr[i]; 15 | 16 | for (j = 1; j < k; j++) 17 | { 18 | if (arr[i + j] > max) 19 | max = arr[i + j]; 20 | } 21 | cout << max << " "; 22 | } 23 | } 24 | 25 | // Driver code 26 | int main() 27 | { 28 | int arr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; 29 | int n = sizeof(arr) / sizeof(arr[0]); 30 | int k = 3; 31 | printKMax(arr, n, k); 32 | return 0; 33 | } 34 | 35 | -------------------------------------------------------------------------------- /Gfg/C++/Remove duplicate element from sorted Linked List.cpp: -------------------------------------------------------------------------------- 1 | int data; 2 | struct Node *next; 3 | Node(int x) { 4 | data = x; 5 | next = NULL; 6 | } 7 | };*/ 8 | // root: head node 9 | Node *removeDuplicates(Node *root) 10 | { 11 | // your code goes here 12 | Node *p=root,*q; 13 | while(p!=NULL){ 14 | while(p->next && p->data==p->next->data){ 15 | q=p->next; 16 | p->next=q->next; 17 | q->next=NULL; 18 | delete q; 19 | 20 | } 21 | p=p->next; 22 | } 23 | return root; 24 | } 25 | -------------------------------------------------------------------------------- /Gfg/C++/Reversearray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | // test cases 8 | while(t--) 9 | { 10 | int n; 11 | cin>>n; 12 | int arr[n]; 13 | // array as input 14 | for(int i = 0; i < n; i++) 15 | cin>>arr[i]; 16 | 17 | // array reversed 18 | for(int i = n-1; i >= 0; i--) 19 | cout< 4 | using namespace std; 5 | int stairs(int a[100][100],int key,int n){ 6 | int i=0; 7 | int j=n-1; 8 | while(i=0){ 9 | if(a[i][j]==key){ 10 | cout<<"Element found at "<key){ 14 | j--; 15 | } 16 | else 17 | i++; 18 | } 19 | cout<<"Element not found"; 20 | return 0; 21 | } 22 | int main(){ 23 | int m,n,a[100][100],key; 24 | cin>>m>>n; 25 | for(int i=0;i>a[i][j]; 28 | } 29 | } 30 | cin>>key; 31 | 32 | stairs(a,key,n); 33 | return 0; 34 | } 35 | //Example:- 36 | //3 3 37 | // 1 2 3 38 | // 4 6 8 39 | // 12 34 56 40 | //6 41 | //Output:- Element found at 1,1. 42 | 43 | 44 | -------------------------------------------------------------------------------- /Gfg/C++/birthday paradox.cpp: -------------------------------------------------------------------------------- 1 | //The following is C++ program to approximate number of people for a given probability. 2 | #include 3 | using namespace std; 4 | typedef long long ll; 5 | int solve(double probabilty) 6 | { 7 | return ceil(sqrt(2 * 365 * log(1 / (1 - probabilty)))); 8 | } 9 | int main() 10 | { 11 | int t = 1; 12 | ios_base::sync_with_stdio(false); 13 | cout.tie(nullptr); 14 | //cin>>t; 15 | while (t--) 16 | { 17 | cout << solve(0.7) << "\n"; //Probality assumed to be 0.7 18 | } 19 | } 20 | //Output : 30 21 | -------------------------------------------------------------------------------- /Gfg/C++/countpairwithgivensum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int n,k; 8 | cin>>n>>k; 9 | int arr[n]; 10 | unordered_mapm; 11 | int c=0; 12 | for(int i=0;i>arr[i]; 15 | } 16 | for(int i=0;i 3 | using namespace std; 4 | 5 | int maxSubArraySum(int array[], int size) 6 | { 7 | int curr_sum = 0; 8 | int max_sum = INT_MIN; 9 | for (int i = 0; i < size; i++) 10 | { 11 | curr_sum += array[i]; 12 | if (curr_sum > max_sum) 13 | max_sum = curr_sum; 14 | if (curr_sum < 0) 15 | curr_sum = 0; 16 | } 17 | return max_sum; 18 | } 19 | 20 | int main() 21 | { 22 | int n; 23 | cout << "Enter no of elements in the array : "; 24 | cin >> n; 25 | int array[n]; 26 | cout << "Enter Elements : "; 27 | for (int i = 0; i < n; i++) 28 | { 29 | cin >> array[i]; 30 | } 31 | cout << "Maximum value of subarray : " << maxSubArraySum(array, n); 32 | return 0; 33 | } -------------------------------------------------------------------------------- /Gfg/C++/first_index_of_array.cpp: -------------------------------------------------------------------------------- 1 | /*Program to find first index of a number in array*/ 2 | #include 3 | using namespace std; 4 | //Function to find first index. 5 | int firstIndex(int arr[],int n,int x){ 6 | if(n==0){//if size of array is 0 then return -1 7 | return -1; 8 | } 9 | if(arr[0]==x){//if element is found at first index itself return 0 10 | return 0; 11 | } 12 | int ans=firstIndex(arr+1,n-1,x);//recursive call 13 | //check for next element 14 | if(ans==-1){//if x is not found return -1 15 | return -1; 16 | } 17 | else{ 18 | return ans+1; 19 | } 20 | } 21 | 22 | int main() { 23 | int n,x,a[200]; 24 | cin>>n; 25 | for(int i=0;i>a[i]; 27 | } 28 | cin>>x; 29 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | //code 6 | int t; 7 | cin>>t; 8 | while(t--) 9 | { 10 | int n,k; 11 | cin>>n>>k; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 16 | } 17 | sort(a,a+n); 18 | for(int i=0;i 0; j--) 15 | 16 | 17 | C[j] = (C[j] + C[j-1])%p; 18 | } 19 | return C[r]; 20 | } 21 | int main() 22 | { 23 | int t; 24 | cin>>t; 25 | while(t--) 26 | { 27 | int n,r; 28 | cin>>n>>r; 29 | /*if(r>n) 30 | { 31 | cout<<"0\n"; 32 | }*/ 33 | int p=1000000007; 34 | cout< 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, num, digit, rev = 0; 7 | 8 | cout << "Enter a positive number: "; 9 | cin >> num; 10 | 11 | n = num; 12 | 13 | do 14 | { 15 | digit = num % 10; 16 | rev = (rev * 10) + digit; 17 | num = num / 10; 18 | } while (num != 0); 19 | 20 | cout << " The reverse of the number is: " << rev << endl; 21 | 22 | if (n == rev) 23 | cout << " The number is a palindrome."; 24 | else 25 | cout << " The number is not a palindrome."; 26 | 27 | return 0; 28 | } 29 | /* 30 | Enter a positive number: 121 31 | The reverse of the number is: 121 32 | The number is a palindrome. 33 | */ 34 | -------------------------------------------------------------------------------- /Gfg/C++/swap using bitwise operator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int x ,y; 6 | cin>>x>>y; 7 | 8 | //swapping using bitwise operator 9 | x = x^y; 10 | y = x^y; 11 | x = x^y; 12 | 13 | cout << x << " " << y << "\n"; 14 | 15 | return 0; 16 | } 17 | //Input:2 3 18 | //Output:3 2 19 | -------------------------------------------------------------------------------- /Gfg/C/Armstrong Number.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() 5 | { 6 | int num,temp=0; 7 | scanf("%d",&num); //taking input 8 | int num2 = num; 9 | while(num>0) 10 | { 11 | temp = temp + pow((num%10),3); 12 | num = num/10; 13 | } 14 | 15 | if(temp==num2) 16 | { 17 | printf("%d is Armstrong.\n",num2); 18 | } 19 | else 20 | { 21 | printf("%d is not Armstrong.\n",num2); 22 | } 23 | 24 | 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Gfg/C/Next Greater Element.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n; 6 | scanf("%d",&n); //Array size; 7 | int arr[n]; 8 | int i; 9 | for(i=0 ; iarr[i]) 19 | { 20 | printf("%d ",arr[j]); 21 | count++; 22 | break; 23 | } 24 | } 25 | if(count!=i) 26 | { 27 | printf("%d ",-1); 28 | count++; 29 | } 30 | } 31 | 32 | 33 | return 0; 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Gfg/C/Palindrome Number.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int num,temp=0; 6 | scanf("%d",&num); //taking input 7 | int num2 = num; 8 | while(num>0) 9 | { 10 | temp = (temp*10) + (num%10); 11 | num = num/10; 12 | } 13 | 14 | if(temp==num2) 15 | { 16 | printf("%d is palindrome.\n",num2); 17 | } 18 | else 19 | { 20 | printf("%d is not palindrome.\n",num2); 21 | } 22 | 23 | 24 | return 0; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /Gfg/C/Value equal to index value.c: -------------------------------------------------------------------------------- 1 | int t; 2 | scanf("%d",&t); 3 | while(t--) 4 | { 5 | int *a,n,i,j=-1; 6 | scanf("%d",&n); 7 | a=(int *)malloc(n*sizeof(int)); 8 | for(i=0;i 2 | 3 | int main() 4 | { 5 | int n; 6 | scanf("%d",&n); //array size 7 | int arr[n]; 8 | int i; 9 | for(i=0 ; ilargest) 18 | { 19 | largest = arr[i]; 20 | } 21 | if(arr[i] 3 | int main() 4 | { 5 | int n,i,a[100]; 6 | 7 | printf("Enter the size of array:"); 8 | scanf("%d",&n); 9 | 10 | for (i=0 ; i=0 ;i--) 22 | { 23 | printf("%d \t",a[i]); 24 | } 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /Gfg/Firstindex.py: -------------------------------------------------------------------------------- 1 | def firstIndex(arr, x): 2 | size=len(arr) 3 | if size<=0: 4 | return -1 5 | if x==arr[0]: 6 | return 0 7 | samllAns = firstIndex(arr[1:], x) 8 | if samllAns == -1: 9 | return -1 10 | else : 11 | return smallAns+1 12 | pass 13 | 14 | # Main 15 | from sys import setrecursionlimit 16 | setrecursionlimit(11000) 17 | n=int(input()) 18 | arr=list(int(i) for i in input().strip().split(' ')) 19 | x=int(input()) 20 | print(firstIndex(arr, x)) 21 | 22 | ''' 23 | Test case 24 | 10 25 | 21 22 46 12 61 21 33 16 99 96 26 | 25 27 | output 28 | -1 29 | ''' 30 | -------------------------------------------------------------------------------- /Gfg/Java/Anagram_Recursion.java: -------------------------------------------------------------------------------- 1 | class Anagram_Rec 2 | { 3 | public static String Anagram(String fix , String s) 4 | { 5 | int l = s.length(); 6 | if(l==1) 7 | { 8 | System.out.println(fix+s); 9 | } 10 | else 11 | { 12 | char ch; 13 | for(int x = 0; x < l; x++) 14 | { 15 | ch = s.charAt(x); 16 | String r = s.substring(0,x)+s.substring(x); 17 | fix = fix+ch; 18 | } 19 | return Anagram(fix , s); 20 | } 21 | return s; 22 | } 23 | public static void main(String args[]) 24 | { 25 | Anagram_Rec ar = new Anagram_Rec(); 26 | System.out.println(ar.Anagram("abc" , "bac")); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Gfg/Java/Armstrong.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Armstrong Number 4 | 5 | Example 1: 6 | 153 = (1*1*1)+(5*5*5)+(3*3*3) 7 | = 1 + 125 + 9 = 153 8 | 153 is an Armstrong number 9 | 10 | Example 2: 11 | 371 = (3*3*3)+(7*7*7)+(1*1*1) 12 | = 37 + 343 + 1 = 371 13 | 14 | */ 15 | 16 | public class Main{ 17 | public static void main(String[] args) { 18 | int c=0,a,temp; 19 | int n=153; 20 | temp=n; 21 | 22 | while(n>0) { 23 | a = n%10; 24 | n = n/10; 25 | c = c+(a*a*a); 26 | } 27 | 28 | if(temp == c) 29 | System.out.println(temp + " is an Armstrong number"); 30 | else 31 | System.out.println(temp + "is not an armstrong number"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Gfg/Java/NthNatural.java: -------------------------------------------------------------------------------- 1 | class NthNatural { 2 | long findNth(long N) 3 | { 4 | //code here 5 | long m=1; 6 | long sum=0; 7 | while(N!=0) 8 | { 9 | long d=N%9; 10 | N=N/9; 11 | sum+=d*m; 12 | m*=10; 13 | } 14 | return sum; 15 | } 16 | } -------------------------------------------------------------------------------- /Gfg/Java/RearrangingArray.java: -------------------------------------------------------------------------------- 1 | class RearrangingArray 2 | { 3 | void prank(long[] a, int n) 4 | { 5 | // code here 6 | long t[] = new long[n]; 7 | for( int i=0;i0) 11 | { 12 | 13 | int n=sc.nextInt(); 14 | int arr[]=new int[n]; 15 | for(int i=0;i=0;i--) 20 | { 21 | System.out.print(arr[i]+" "); 22 | } 23 | t--; 24 | System.out.println(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Gfg/Java/reverse-string.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public void helper(char[] s, int left, int right) { 3 | if (left >= right) return; 4 | char tmp = s[left]; 5 | s[left++] = s[right]; 6 | s[right--] = tmp; 7 | helper(s, left, right); 8 | } 9 | 10 | public void reverseString(char[] s) { 11 | helper(s, 0, s.length - 1); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Gfg/Java/second_largestnum.java: -------------------------------------------------------------------------------- 1 | class solution{ 2 | int lar=-1; int sec_lar = -1; 3 | 4 | for(int i=0;i 0: 14 | digit = cube % 10 15 | sum += digit ** order 16 | cube //= 10 17 | 18 | # display the result 19 | if num == sum: 20 | print(num,"is an Armstrong number") 21 | else: 22 | print(num,"is not an Armstrong number") 23 | # ex-1 24 | # Enter a number: 153 25 | # 153 is an Armstrong number 26 | # ex-2 27 | # Enter a number: 121 28 | # 121 is not an Armstrong number 29 | -------------------------------------------------------------------------------- /Gfg/Python/CountAndSay.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def countAndSay(self, n): 3 | if (n == 1): 4 | return ("1") 5 | 6 | s = self.countAndSay(n-1) 7 | 8 | ret = "" 9 | cnt = 1 10 | i = 1 11 | while i < len(s) + 1: 12 | if i < len(s) and s[i] == s[i-1]: 13 | cnt += 1 14 | else: 15 | ret += str(cnt) + str(s[i-1]) 16 | cnt = 1 17 | i += 1 18 | 19 | return (ret) 20 | -------------------------------------------------------------------------------- /Gfg/Python/Find_n_in_array.py: -------------------------------------------------------------------------------- 1 | # program to check if n is present in an array. 2 | #we can do it using linear Search or binary Search 3 | #linear search approach 4 | #def linearSearch(a,n): 5 | # for i in range(len(a)): 6 | # if a[i]==n: 7 | # return True 8 | 9 | # return False 10 | 11 | 12 | 13 | #binary search approach 14 | def binarySearch(a,n): 15 | l=0 16 | h=len(a)-1; 17 | if l<=h: 18 | mid=(l+h)//2 19 | if a[mid]==n: 20 | return True 21 | elif a[mid]>n: 22 | h=mid-1 23 | else : 24 | l=mid+1 25 | return False 26 | 27 | 28 | arr=[] 29 | m=int(input("Enter size of array : ")) 30 | for i in range(m): 31 | e=int(input()) 32 | arr.append(e) 33 | n=int(input("Enter element to be searched : ")) 34 | #print(linearSearch(arr,n)) 35 | print(binarySearch(arr,n)) 36 | 37 | #Example: 38 | #size = 5 39 | # 5 4 0 1 2 40 | #1 41 | #true 42 | 43 | -------------------------------------------------------------------------------- /Gfg/Python/Kthlargestelement.py: -------------------------------------------------------------------------------- 1 | class Solution(object): 2 | def findKthLargest(self, nums, k): 3 | nums.sort() 4 | if k ==1: 5 | return nums[-1] 6 | temp = 1 7 | return nums[len(nums)-k] 8 | obj1 = Solution() 9 | n=int(input("size ")); 10 | a=[] 11 | for i in range(0,n): 12 | ele=int(input("Enter array elements ")) 13 | a.append(ele) 14 | k=int(input()) 15 | print(obj1.findKthLargest(a,k)) -------------------------------------------------------------------------------- /Gfg/Python/Lucky alive person.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def lucky_alive(n:int): 4 | 5 | # to calculate the number of bits in 6 | # the binary equivalent of n 7 | len = int(math.log2(n)) + 1 8 | 9 | # Finding complement by inverting the 10 | # bits one by one from last 11 | n2 = n 12 | 13 | for i in range(len): 14 | # XOR of n2 with (1<=1 23 | 24 | #main() 25 | print(Pascal(6)) 26 | -------------------------------------------------------------------------------- /Gfg/Python/trapping_rainwater.py: -------------------------------------------------------------------------------- 1 | def trapping_rainwater(arr,n): 2 | # max water that can be stored 3 | total_water=0 4 | 5 | for i in range(1,n-1): 6 | # max element from left 7 | left=arr[i] 8 | for j in range(i): 9 | left=max(left,arr[j]) 10 | 11 | # max element from rightg 12 | right=arr[i] 13 | for j in range(i+1,n): 14 | right=max(right,arr[j]) 15 | # update maximum water 16 | total_water=total_water+(min(left,right)-arr[i]) 17 | return total_water 18 | 19 | if __name__=="__main__": 20 | array=[] 21 | n=int(input("size of array ?")) 22 | for k in range(0,n): 23 | a=int(input("array elements")) 24 | array.append(a) 25 | 26 | ans=trapping_rainwater(array,n) 27 | print(ans) 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Gfg/negitivenumber.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.*; 3 | 4 | class GFG { 5 | 6 | static void rearrange(int arr[], int n) 7 | { 8 | int j = 0, temp; 9 | for (int i = 0; i < n; i++) { 10 | if (arr[i] < 0) { 11 | if (i != j) { 12 | temp = arr[i]; 13 | arr[i] = arr[j]; 14 | arr[j] = temp; 15 | } 16 | j++; 17 | } 18 | } 19 | } 20 | 21 | // A utility function to print an array 22 | static void printArray(int arr[], int n) 23 | { 24 | for (int i = 0; i < n; i++) 25 | System.out.print(arr[i] + " "); 26 | } 27 | 28 | // Driver code 29 | public static void main(String args[]) 30 | { 31 | int arr[] = { -1, 2, -3, 4, 5, 6, -7, 8, 9 }; 32 | int n = arr.length; 33 | 34 | rearrange(arr, n); 35 | printArray(arr, n); 36 | } 37 | } 38 | /*test cases 39 | Input: -12, 11, -13, -5, 6, -7, 5, -3, -6 40 | Output: -12 -13 -5 -7 -3 -6 11 6 5*/ 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /Gfg/searchingarray.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main () 4 | { 5 | int arr[10], n, i, max, min; 6 | cout << "Enter the size of the array : "; 7 | cin >> n; 8 | cout << "Enter the elements of the array : "; 9 | for (i = 0; i < n; i++) 10 | cin >> arr[i]; 11 | max = arr[0]; 12 | for (i = 0; i < n; i++) 13 | { 14 | if (max < arr[i]) 15 | max = arr[i]; 16 | } 17 | min = arr[0]; 18 | for (i = 0; i < n; i++) 19 | { 20 | if (min > arr[i]) 21 | min = arr[i]; 22 | } 23 | cout << "Largest element : " << max< 2 | #define endl '\n' 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int n,m; 8 | cin>>n>>m; 9 | int arr[n][m]; 10 | 11 | for(int i=0 ; i>arr[i][j]; 16 | } 17 | } 18 | 19 | int k; 20 | cin>>k; 21 | 22 | int temp; 23 | for(int i=0 ; i arr[j+1][k]) 28 | { 29 | for(int l=0 ; l 2 | #define ll long long int 3 | using namespace std; 4 | int main() 5 | { 6 | ll n,m; 7 | cin>>n>>m; 8 | ll a[n],b[m]; 9 | for(ll i=0;i>a[i]; 10 | for(ll i=0;i>b[i]; 11 | ll c=0; 12 | for(ll i=1;i<=100;i++) 13 | { 14 | bool ha=true,haa=true; 15 | for(ll j=0;j 2 | using namespace std; 3 | #define endl '\n' 4 | #define ll long long int 5 | int main() 6 | { 7 | ll n; 8 | cin>>n; 9 | ll arr[n]; 10 | ll chk[n]; 11 | for(ll i = 0; i>arr[i]; 14 | chk[i] = 1; 15 | } 16 | for(ll i = 1; iarr[i-1] && !(chk[i]>chk[i-1])) 19 | { 20 | chk[i]= chk[i-1] + 1; 21 | } 22 | } 23 | 24 | for(ll i = n-2; i>=0; i--) 25 | { 26 | if(arr[i]>arr[i+1] && !(chk[i]>chk[i+1])) 27 | { 28 | chk[i]= chk[i+1] + 1; 29 | } 30 | } 31 | ll sum = 0; 32 | for(ll i = 0; i 2 | using namespace std; 3 | 4 | #define pb push_back 5 | #define mp make_pair 6 | #define REP(i, n) for (int i = 0; i < (int)(n); ++i) 7 | typedef long long LL; 8 | typedef pair PII; 9 | 10 | int a[3], b[3]; 11 | 12 | int main() 13 | { 14 | REP(i, 3) scanf("%d", a + i); 15 | REP(i, 3) scanf("%d", b + i); 16 | int x = 0, y = 0; 17 | REP(i, 3) if (a[i] > b[i]) 18 | { 19 | ++x; 20 | } else if (a[i] < b[i]) 21 | { 22 | ++y; 23 | } 24 | printf("%d %d\n", x, y); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /Hackerank/C++/Count Occurences Sorted Array BS.cpp: -------------------------------------------------------------------------------- 1 | // C++ program to count occurrences of an element in a sorted array. 2 | # include 3 | using namespace std; 4 | 5 | 6 | int count(int a[], int element, int n) 7 | { 8 | int *low = lower_bound(a, a+n, element); 9 | if (low == (a + n) || *low != element) 10 | return 0; 11 | int *high = upper_bound(low, a+n, element); 12 | return high - low; 13 | } 14 | 15 | 16 | int main() 17 | { 18 | int a[] = {1, 1, 2, 2, 2, 3, 4, 5}; 19 | int element = 2; // Element to be counted in a[] 20 | int n = sizeof(a)/sizeof(a[0]); 21 | int c = count(a, element, n); 22 | printf(" %d occurs %d times ", element, c); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Hackerank/C++/Digit Frequency.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #define endl '\n' 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string str; 8 | cin>>str; 9 | int arr[10] = {0,0,0,0,0,0,0,0,0,0}; 10 | for(int i=0 ; i 2 | 3 | using namespace std; 4 | 5 | int solve(int n, int p) 6 | { 7 | // Complete this function 8 | if(p == 1 || p == n) 9 | { 10 | return 0; 11 | } 12 | int ans = 1 + (p-2)/2; 13 | if(n%2 == 0) 14 | { 15 | return min(ans, (int)(1 + (n-p-1)/2)); 16 | } 17 | 18 | return min((int)(n-p)/2, ans); 19 | } 20 | 21 | int main() 22 | { 23 | int n; 24 | cin >> n; 25 | int p; 26 | cin >> p; 27 | int result = solve(n, p); 28 | cout << result << endl; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Hackerank/C++/Electronics Shop.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | 7 | int s,n,m,a,res = -1,keyboard[1001],usb[1001]; 8 | 9 | cin >> s >> n >> m; 10 | for(int i = 0; i < n; i++)cin >> keyboard[i]; 11 | for(int i = 0; i < m; i++)cin >> usb[i]; 12 | 13 | for(int i = 0; i < n; i++){ 14 | for(int j = 0; j < m; j++){ 15 | if(keyboard[i]+usb[j] <= s)res = max(res,keyboard[i]+usb[j]); 16 | } 17 | } 18 | cout << res << endl; 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Hackerank/C++/Geometric Distribution 1.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | double p = 0.333; 12 | double q = 1.0 - p; 13 | 14 | //4 = 5-1; 15 | 16 | double g_prob = pow(q, 4)*p; 17 | 18 | printf("%0.3f", g_prob); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Hackerank/C++/Geometric Distribution 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | 12 | double p = 0.333; 13 | double q = 1 - p; 14 | 15 | double g_prob = 0.0; 16 | 17 | for(auto i=1; i<=5; i++) 18 | { 19 | g_prob += pow(q, i-1)*p; 20 | } 21 | 22 | printf("%0.3f", g_prob); 23 | 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Hackerank/C++/Largest prime factor.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler003/problem 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int T; 8 | cin>>T; 9 | while(T--) { 10 | long N; 11 | cin>>N; 12 | while(N%2==0) 13 | N /= 2; 14 | if (N==1) { 15 | cout<<"2"<2) 25 | cout< 4 | using namespace std; 5 | 6 | int main() { 7 | unsigned long long arr[501][501]; 8 | for (int i = 0; i < 501; i++) { 9 | arr[i][0] = 1; 10 | arr[0][i] = 1; 11 | } 12 | for (int i = 1; i < 501; i++) { 13 | for (int j = 1; j < 501; j++) { 14 | arr[i][j] = (arr[i - 1][j] + arr[i][j - 1]) % 1000000007; 15 | } 16 | } 17 | int T; 18 | cin >> T; 19 | while (T--) { 20 | int M, N; 21 | cin >> N >> M; 22 | cout << arr[N][M]<< endl; 23 | } 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /Hackerank/C++/Magic Square.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | vector> valid_squares = {{8,1,6,3,5,7,4,9,2}, {4,3,8,9,5,1,2,7,6}, {2,9,4,7,5,3,6,1,8},{6,7,2,1,5,9,8,3,4},{6,1,8,7,5,3,2,9,4},{8,3,4,1,5,9,6,7,2},{4,9,2,3,5,7,8,1,6},{2,7,6,9,5,1,4,3,8}}; 11 | int a[9]; 12 | for(int i=0;i<9;i++) cin>>a[i]; 13 | int best = 1000000; 14 | for(int i=0;i<8;i++){ 15 | int diff = 0; 16 | for(int j=0;j<9;j++) diff += abs(a[j]-valid_squares[i][j]); 17 | if (diff 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | double l1 = 0.88, l2 = 1.55; 12 | 13 | double p1 = 160 + 40*(l1 + (l1*l1)); 14 | double p2 = 128 + 40*(l2 + (l2*l2)); 15 | 16 | printf("%0.3f\n%0.3f", p1, p2); 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Hackerank/C++/Poisson Distribution.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | /* 9 | Given: 10 | (lemda) = 2.5 11 | k = 5; 12 | prob = (((lemda)^k)*(e)^(-lemda))/fact(k); 13 | */ 14 | 15 | int fact(int n) 16 | { 17 | if(n < 2) 18 | return 1; 19 | return n*fact(n-1); 20 | } 21 | 22 | int main() { 23 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 24 | 25 | double prob = ((pow(2.5, 5))*(pow(2.71, (-2.5))))/fact(5); 26 | printf("%0.3f", prob); 27 | return 0; 28 | } 29 | -------------------------------------------------------------------------------- /Hackerank/C++/Smallest multiple.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler005/problem 2 | 3 | #include 4 | 5 | int main(){ 6 | int t; 7 | scanf("%d",&t); 8 | for(int a0 = 0; a0 < t; a0++){ 9 | int n; 10 | scanf("%d",&n); 11 | long i; 12 | int j; 13 | for (i=1; ; i++) { 14 | for (j=1; j<=n; j++) { 15 | if (i%j != 0) { 16 | break; 17 | } 18 | } 19 | if (j == n+1) { 20 | printf("%ld\n", i); 21 | break; 22 | } 23 | } 24 | } 25 | return 0; 26 | } -------------------------------------------------------------------------------- /Hackerank/C++/Staircase.cpp: -------------------------------------------------------------------------------- 1 | //Problem link: https://www.hackerrank.com/challenges/staircase/problem 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | //Initialize variables 9 | int num; 10 | 11 | //Enter size: 12 | cout << "Enter size of staircase: "; 13 | cin >> num; 14 | 15 | //Print out corresponding staircase 16 | for (int i = 1; i <= num; i++) 17 | { 18 | for(int j = i; j <= num - 1; j++) 19 | { 20 | cout<<" "; 21 | } 22 | for(int k = 1; k <= i; k++) 23 | { 24 | cout<<"#"; 25 | } 26 | cout << endl; 27 | } 28 | return 0; 29 | } 30 | 31 | /* 32 | 33 | Enter size of staircase: 6 34 | # 35 | ## 36 | ### 37 | #### 38 | ##### 39 | ###### 40 | 41 | */ 42 | -------------------------------------------------------------------------------- /Hackerank/C++/Sum square difference.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler006/problem 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | int t; 8 | cin >> t; 9 | for(int a0 = 0; a0 < t; a0++){ 10 | long n; 11 | cin >> n; 12 | cout<<(n-1)*n*(n+1)*(3*n+2)/12<<"\n"; 13 | } 14 | return 0; 15 | } -------------------------------------------------------------------------------- /Hackerank/C++/The Central Limit Theorem 3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | double normal_dist(double m, double sd, double x) 9 | { 10 | double p = 0.5*(1 + erf((x-m)/(sd*sqrt(2.0)))); 11 | return p ; 12 | } 13 | 14 | int main() { 15 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 16 | double mean = 500; 17 | double std = 80; 18 | int n = 100; 19 | double zScore = 1.96; 20 | double marginOfError = zScore * std/sqrt(n); 21 | printf("%0.2f\n%0.2f", mean - marginOfError, mean + marginOfError); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hackerank/C++/The Central Limit Theorem 2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | double normal_dist(double m, double sd, double x) 9 | { 10 | double p = 0.5*(1 + erf((x-m)/(sd*sqrt(2.0)))); 11 | return p; 12 | } 13 | 14 | int main() { 15 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 16 | double m = 100*2.4, sd = sqrt(100)*2.0, x = 250; 17 | printf("%0.4f", normal_dist(m, sd, x)); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Hackerank/C++/The Central Limit Theorem.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | double normal_dist(double m, double sd, double x) 9 | { 10 | double p = 0.5*(1 + erf((x-m)/(sd*sqrt(2.0)))); 11 | return p; 12 | } 13 | 14 | int main() { 15 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 16 | double m = 49*205, sd = sqrt(49)*15, x = 9800; 17 | printf("%0.4f", normal_dist(m, sd, x)); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Hackerank/C++/hackerank_change_time_format.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | void convert(string s){ 5 | int a=s[0]-'0'; 6 | int b=s[1]-'0'; 7 | int c=(s[0]-'0')*100000+(s[1]-'0')*10000+(s[3]-'0')*1000+(s[4]-'0')*100+(s[6]-'0')*10+s[7]-'0'; 8 | if(s[8]=='P'){ 9 | if(c>120000){ 10 | s[0]=s[0]; 11 | s[1]=s[1]; 12 | } 13 | else{ 14 | s[0]+=1; 15 | s[1]+=2; 16 | } 17 | } 18 | else{ 19 | if(a*10+b==12){ 20 | s[0]='0'; 21 | s[1]='0'; 22 | } 23 | } 24 | std::cout< 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | int t,i; 8 | scanf("%d",&t); 9 | long int arr[1000]; 10 | long int s=0; 11 | for(i=0;i 2 | #include 3 | 4 | int main() 5 | { 6 | int num, *arr,*arr2,i; 7 | scanf("%d", &num); 8 | arr = (int*) malloc(num * sizeof(int)); 9 | for(i = 0; i < num; i++) { 10 | scanf("%d", arr + i); 11 | } 12 | arr2 = (int*) malloc(num * sizeof(int)); 13 | for(i=1;i<=num;i++) 14 | { 15 | arr2[i-1] = arr[num-i]; 16 | } 17 | for(i = 0; i < num; i++) 18 | printf("%d ", *(arr2 + i)); 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /Hackerank/C/Digit Frequency.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 8 | char s[1001]; 9 | scanf("%[^\n]%*c", s); 10 | int arr[10] = {0}; 11 | for(int i = 0; i < strlen(s); i++){ 12 | if(s[i] >= '0' && s[i] <= '9') 13 | arr[s[i] - '0']++; 14 | } 15 | for(int i = 0; i < 10; i++) 16 | printf("%d ", arr[i]); 17 | printf("\n"); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /Hackerank/C/Divisible Sum Pair.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | int n, k; 6 | scanf("%d %d", &n, &k); 7 | int count = 0; 8 | int nums[n]; 9 | for (int i = 0; i < n; i++) 10 | { 11 | scanf("%d", &nums[i]); 12 | for (int j = 0; j < i; j++) 13 | count += (nums[i] + nums[j]) % k == 0; 14 | } 15 | printf("%d", count); 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /Hackerank/C/Equalize the Array.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n,i,j,k=0,x,y=0; 5 | scanf("%d",&n); 6 | int a[n]; 7 | for(i=0;i 4 | 5 | int main(){ 6 | int t; 7 | scanf("%d",&t); 8 | for(int a0 = 0; a0 < t; a0++){ 9 | long n; 10 | scanf("%ld",&n); 11 | long prev=1, curr=2, next=0, sum=0; 12 | while (next 2 | int main() { 3 | int n, e = 0; 4 | scanf("%d",&n); 5 | int a[n]; 6 | for (int i = 0; i < n; i++) { 7 | scanf("%d",&a[i]); 8 | } 9 | for (int i = 0; i < n; i++) { 10 | 11 | if (a[i] >= 38) { 12 | 13 | for (int j = a[i]; e != 1; j++) { 14 | if (j % 5 == 0) { 15 | if (j - a[i] < 3) { 16 | a[i] = j; 17 | } else if (j - a[i] == 3) { 18 | a[i] = a[i]; 19 | } 20 | e = 1; 21 | } 22 | } 23 | e = 0; 24 | 25 | } 26 | 27 | else { 28 | a[i] = a[i]; 29 | } 30 | } 31 | for (int i = 0; i < n; i++) { 32 | printf("%d\n",a[i]); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Hackerank/C/Jumping on the clouds.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main(){ 10 | int n,i; 11 | scanf("%d",&n); 12 | int *c = malloc(sizeof(int) * n); 13 | for(int ci = 0; ci < n; ci++){ 14 | scanf("%d ",&c[ci]); 15 | } 16 | int j=0; 17 | for(i=0;i 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | int main() 15 | { 16 | int n, d, i, j, temp; 17 | scanf("%d\t%d", &n, &d); 18 | 19 | int *arr = malloc(sizeof(int)*n); 20 | for(i=0;i 2 | #define MAX 100000 3 | 4 | int main(void) 5 | { 6 | int arr[MAX],i,n,d; 7 | scanf("%d%d",&n,&d); 8 | for(i=0;i 2 | int main() 3 | { 4 | int n,i,max,ans; 5 | scanf("%d", &n); 6 | int a[n],h[6]={0}; 7 | for(i = 0; i < n; i++) 8 | { 9 | scanf("%d",&a[i]); 10 | h[a[i]]++; 11 | } 12 | max=h[1]; 13 | for(i = 2; i < 6; i++) 14 | { 15 | if(max 4 | 5 | int main(){ 6 | int t; 7 | scanf("%d",&t); 8 | for(int a0 = 0; a0 < t; a0++){ 9 | long n; 10 | scanf("%ld",&n); 11 | long k, sum=0; 12 | k = (n-1)/3; 13 | sum = sum + 3*k*(k+1)/2; 14 | k = (n-1)/5; 15 | sum = sum + 5*k*(k+1)/2; 16 | k = (n-1)/15; 17 | sum = sum - 15*k*(k+1)/2; 18 | printf("%ld\n", sum); 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /Hackerank/C/Printing Pattern Using Loops.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int n; 9 | scanf("%d", &n); 10 | // Complete the code to print the pattern. 11 | int l = 2*n-1; 12 | for(int i=0;i 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | char *s; 8 | s = malloc(1024 * sizeof(char)); 9 | scanf("%[^\n]", s); 10 | s = realloc(s, strlen(s) + 1); 11 | //Write your logic to print the tokens of the sentence here. 12 | int len = strlen(s); 13 | for(int i = 0; i < len; i++) { 14 | if(s[i] == ' ') { 15 | printf("\n"); 16 | } 17 | else { 18 | printf("%c", s[i]); 19 | } 20 | } 21 | free(s); 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /Hackerank/C/Sales by Match.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | 8 | int i,t,c,j,a[101]; 9 | scanf("%d",&t); 10 | for(i=0;i0){ 16 | c++; 17 | a[i]=0; 18 | a[j]=0; 19 | } 20 | } 21 | } 22 | printf("%d",c); 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Hackerank/C/Subarray Division.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | int main() 10 | { 11 | int n; 12 | scanf("%d",&n); 13 | int *squares = malloc(sizeof(int) * n); 14 | for(int squares_i = 0; squares_i < n; squares_i++) 15 | { 16 | scanf("%d",&squares[squares_i]); 17 | } 18 | int d; 19 | int m; 20 | scanf("%d %d",&d,&m); 21 | int count = 0; 22 | for (int i = 0;i <= n-m; ++i) 23 | { 24 | int sum = 0; 25 | for (int j = i;j < i+m; ++j) 26 | { 27 | sum += squares[j]; 28 | } 29 | if (sum == d) 30 | ++count; 31 | } 32 | printf("%d",count); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Hackerank/C/Time conversion.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() { 7 | char s[20]; 8 | scanf("%s",s); 9 | if(s[strlen(s)-2]=='P' || s[strlen(s)-2]=='p') 10 | { 11 | if(!(s[0]=='1' && s[1]=='2')) 12 | { 13 | 14 | s[0]=s[0]+1; 15 | s[1]=s[1]+2; 16 | } 17 | } 18 | else if(s[strlen(s)-2]=='A' || s[strlen(s)-2]=='a') 19 | { 20 | if(s[0]=='1' && s[1]=='2') 21 | { 22 | s[0]='0'; 23 | s[1]='0'; 24 | } 25 | } 26 | s[strlen(s)-2]='\0'; 27 | printf("%s",s); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Hackerank/C/Variadic functions in C.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define MIN_ELEMENT 1 7 | #define MAX_ELEMENT 1000000 8 | int sum (int count,...) { 9 | va_list arr; 10 | int t = 0; 11 | va_start(arr, count); 12 | while(count--){ 13 | t += va_arg(arr, int); 14 | } 15 | return t; 16 | } 17 | 18 | int min(int count,...) { 19 | va_list arr; 20 | int mn = MIN_ELEMENT; 21 | va_start(arr, count); 22 | while(count--){ 23 | if(mn > va_arg(arr, int)) 24 | mn = va_arg(arr, int); 25 | } 26 | return mn; 27 | } 28 | 29 | int max(int count,...) { 30 | va_list arr; 31 | int mx = MAX_ELEMENT; 32 | va_start(arr, count); 33 | while(count--){ 34 | if(mx < va_arg(arr, int)) 35 | mx = va_arg(arr, int); 36 | } 37 | return mx; 38 | } 39 | -------------------------------------------------------------------------------- /Hackerank/Python/Alternating Characters.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | import math 3 | import os 4 | import random 5 | import re 6 | import sys 7 | 8 | # Complete the alternatingCharacters function below. 9 | def alternatingCharacters(s): 10 | count=0 11 | for i in range(1,len(s)): 12 | if s[i]==s[i-1]: 13 | count+=1 14 | return(count) 15 | 16 | if __name__ == '__main__': 17 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 18 | q = int(input()) 19 | for q_itr in range(q): 20 | s = input() 21 | result = alternatingCharacters(s) 22 | fptr.write(str(result) + '\n') 23 | fptr.close() 24 | -------------------------------------------------------------------------------- /Hackerank/Python/Balanced_brackets.py: -------------------------------------------------------------------------------- 1 | def check(my_string): 2 | 3 | brackets = ['()', '{}', '[]'] 4 | 5 | while any(x in my_string for x in brackets): 6 | 7 | for br in brackets: 8 | 9 | my_string = my_string.replace(br, '') 10 | 11 | return not my_string 12 | 13 | 14 | string =input(" Enter parenthesis ") 15 | 16 | print(string, "-", "Balanced" 17 | 18 | if check(string) else "Unbalanced") -------------------------------------------------------------------------------- /Hackerank/Python/Binomial Distribution 1.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | def factorial(n): 3 | if n==0 or n==1: 4 | return 1 5 | else: 6 | return n*factorial(n-1) 7 | 8 | def nCr(n,r): 9 | return factorial(n)/(factorial(r) * factorial(n-r)) 10 | 11 | arr=map(float,input().split()) 12 | p=arr[0]/sum(arr) 13 | q=arr[1]/sum(arr) 14 | sum1=0 15 | for i in range(3,7): 16 | temp=nCr(6,i) 17 | temp1=(p**i)*(q**(6-i)) 18 | sum1+= temp*temp1 19 | print (round(sum1,3)) 20 | -------------------------------------------------------------------------------- /Hackerank/Python/Caesar Cipher.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | import math 3 | import os 4 | import random 5 | import re 6 | import sys 7 | 8 | # Complete the caesarCipher function below. 9 | def caesarCipher(s, k): 10 | temp=[] 11 | for char in s: 12 | temp.append(ord(char)) 13 | 14 | for i in range(n): 15 | if 65<=temp[i]<=90: 16 | temp[i]=(65+(temp[i]-65+k)%26) 17 | elif 97<=temp[i]<=122: 18 | temp[i]=(97+(temp[i]-97+k)%26) 19 | return "".join(map(chr,temp)) 20 | 21 | if __name__ == '__main__': 22 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 23 | n = int(input()) 24 | s = input() 25 | k = int(input()) 26 | result = caesarCipher(s, k) 27 | fptr.write(result + '\n') 28 | fptr.close() 29 | -------------------------------------------------------------------------------- /Hackerank/Python/Digit Power Sum.py: -------------------------------------------------------------------------------- 1 | # Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler119/problem 2 | import math 3 | MAX = 10**100 4 | 5 | def ConvertToBase(num, base): 6 | res = 0 7 | digits = 0 8 | 9 | while(num > 0): 10 | res += int(num % base) 11 | digits += 1 12 | num //= base 13 | 14 | return res if digits >= 2 else -1 15 | 16 | B = int(input()) 17 | ans = set() 18 | limit = 999 if B <= 10 else (B * 50) 19 | 20 | for i in range(2, limit + 1): 21 | p = i * i 22 | 23 | while(p < MAX): 24 | if(p < B): 25 | p *= i 26 | continue 27 | digit_sum = ConvertToBase(p, B) 28 | 29 | if(digit_sum == i): ans.add(p) 30 | p *= i 31 | 32 | output = [str(num) for num in sorted(list(ans))] 33 | print(" ".join(output)) 34 | -------------------------------------------------------------------------------- /Hackerank/Python/Factorial digit sum.py: -------------------------------------------------------------------------------- 1 | # Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler020/problem 2 | 3 | def factorial(n): 4 | p = 1 5 | for i in range(1, n+1): 6 | p *= i 7 | return p 8 | 9 | for _ in range(int(input())): 10 | ls = str(factorial(int(input()))) 11 | sum = 0 12 | for i in ls: 13 | sum += int(i) 14 | print(sum) 15 | -------------------------------------------------------------------------------- /Hackerank/Python/Interquartile Range.py: -------------------------------------------------------------------------------- 1 | def find_median(arr): 2 | if len(arr) % 2 == 1: 3 | return arr[len(arr) // 2] 4 | else: 5 | return (arr[len(arr) // 2] + arr[len(arr) // 2 - 1]) / 2 6 | 7 | 8 | # create array 9 | n = int(input()) 10 | values = list(map(int, input().split())) 11 | freq = list(map(int, input().split())) 12 | arr = [] 13 | for i in range(n): 14 | arr += [values[i]] * freq[i] 15 | arr = sorted(arr) 16 | 17 | # find iqr 18 | iqr = float(find_median(arr[len(arr) // 2 + len(arr) % 2:]) - find_median(arr[:len(arr)//2])) 19 | print(iqr) 20 | -------------------------------------------------------------------------------- /Hackerank/Python/Large sum.py: -------------------------------------------------------------------------------- 1 | # Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler013/problem 2 | 3 | sum = 0 4 | for _ in range(int(input())): 5 | sum += int(input()) 6 | print(str(sum)[:10]) 7 | -------------------------------------------------------------------------------- /Hackerank/Python/Largest product in a series.py: -------------------------------------------------------------------------------- 1 | # Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler008/problem 2 | 3 | for _ in range(int(input())): 4 | N, K = map(int, input().split()) 5 | number = input() 6 | p = list() 7 | for i in range(len(number)-K): 8 | product=1 9 | str = number[i:i+K] 10 | for ch in str: 11 | product = product*int(ch) 12 | p.append(product) 13 | print(max(p)) -------------------------------------------------------------------------------- /Hackerank/Python/Linear Algebra.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | N = int(input()) 3 | A = numpy.array([input().split() for _ in range(N)], float) 4 | print(round(numpy.linalg.det(A),2)) 5 | -------------------------------------------------------------------------------- /Hackerank/Python/Mark and Toys.py: -------------------------------------------------------------------------------- 1 | # Link of the Problem: https://www.hackerrank.com/challenges/mark-and-toys/problem 2 | import math 3 | import os 4 | import random 5 | import re 6 | import sys 7 | 8 | def maximumToys(prices, k): 9 | prices.sort() 10 | s = 0 11 | c = 0 12 | for i in range(len(prices)): 13 | if s+prices[i]<=k: 14 | s+=prices[i] 15 | c+=1 16 | return c 17 | 18 | if __name__ == '__main__': 19 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 20 | 21 | nk = input().split() 22 | 23 | n = int(nk[0]) 24 | 25 | k = int(nk[1]) 26 | 27 | prices = list(map(int, input().rstrip().split())) 28 | 29 | result = maximumToys(prices, k) 30 | 31 | fptr.write(str(result) + '\n') 32 | 33 | fptr.close() 34 | -------------------------------------------------------------------------------- /Hackerank/Python/Multiple Linear Regression.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | from sklearn import linear_model 3 | 4 | first = list(map(int, str.split(input(), " "))) 5 | m, n = first[0], first[1] 6 | 7 | data = [list(float(x) for x in input().split()) for i in range(n)] 8 | 9 | x = [[item[i] for i in range(m)] for item in data] 10 | y = [item[-1] for item in data] 11 | lm = linear_model.LinearRegression() 12 | lm.fit(x, y) 13 | a = lm.intercept_ 14 | b = lm.coef_ 15 | 16 | for i in range(int(input())): 17 | data = list(map(float, input().split())) 18 | ans = [b[j]*data[j] for j in range(m)] 19 | print(a+sum(ans)) 20 | 21 | -------------------------------------------------------------------------------- /Hackerank/Python/No Idea!.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | io = input().split() 3 | m = int(io[0]) 4 | n = int(io[1]) 5 | storage = list() 6 | count = 0 7 | storage = list(map(int, input().strip().split())) 8 | A = set(map(int, input().strip().split())) 9 | B = set(map(int, input().strip().split())) 10 | for i in storage: 11 | if i in A: 12 | count = count+1 13 | if i in B: 14 | count = count-1 15 | print(count) 16 | -------------------------------------------------------------------------------- /Hackerank/Python/Pangrams.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | import math 3 | import os 4 | import random 5 | import re 6 | import sys 7 | 8 | # Complete the pangrams function below. 9 | ascii_array = [] 10 | def pangrams(s): 11 | lower_s = s.lower() 12 | for i in range(len(lower_s)): 13 | ascii_array.append(ord(lower_s[i])) 14 | for i in range(97,123): 15 | if i not in ascii_array: 16 | return "not pangram" 17 | return 'pangram' 18 | 19 | if __name__ == '__main__': 20 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 21 | s = input() 22 | result = pangrams(s) 23 | fptr.write(result + '\n') 24 | fptr.close() 25 | -------------------------------------------------------------------------------- /Hackerank/Python/Power digit sum.py: -------------------------------------------------------------------------------- 1 | # Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler016/problem 2 | 3 | for _ in range(int(input())): 4 | print(sum((map(int, str(2**int(input())))))) 5 | -------------------------------------------------------------------------------- /Hackerank/Python/Quartiles.py: -------------------------------------------------------------------------------- 1 | def find_median(arr): 2 | if len(arr) % 2 == 1: 3 | return arr[len(arr) // 2] 4 | else: 5 | return (arr[len(arr) // 2] + arr[len(arr) // 2 - 1]) // 2 6 | 7 | 8 | n = input() 9 | arr = sorted(list(map(int, input().split()))) 10 | print(find_median(arr[:len(arr)//2])) 11 | print(find_median(arr)) 12 | print(find_median(arr[len(arr) // 2 + len(arr) % 2:])) 13 | -------------------------------------------------------------------------------- /Hackerank/Python/Recursive digit sum.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the superDigit function below. 10 | def superDigit(n, k): 11 | n = str(sum([int(i) for i in n])*k); 12 | k = 1; 13 | if len(n) > 1: 14 | n = sum([int(i) for i in n]); 15 | return superDigit(str(n),k); 16 | return n; 17 | 18 | 19 | if __name__ == '__main__': 20 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 21 | 22 | nk = input().split() 23 | 24 | n = nk[0] 25 | 26 | k = int(nk[1]) 27 | 28 | result = superDigit(n, k) 29 | 30 | fptr.write(str(result) + '\n') 31 | 32 | fptr.close() 33 | -------------------------------------------------------------------------------- /Hackerank/Python/Special Pythagorean triplet.py: -------------------------------------------------------------------------------- 1 | # Problem Link: https://www.hackerrank.com/contests/projecteuler/challenges/euler009/problem 2 | 3 | for _ in range(int(input())): 4 | N = int(input()) 5 | ls = list() 6 | for a in range(1, N): 7 | b = (N*N-2*a*N)/(2*N-2*a) 8 | if b!=int(b) or b<=a: 9 | continue 10 | else: 11 | b=int(b) 12 | c = N-a-b 13 | if c<=b: 14 | continue 15 | ls.append(a*b*c) 16 | if ls: 17 | print(max(ls)) 18 | else: 19 | print("-1") 20 | -------------------------------------------------------------------------------- /Hackerank/Python/Standard Deviation.py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | arr = list(map(int, input().split())) 3 | avg = sum(arr) / len(arr) 4 | std = (sum([(arr[x] - avg)**2 for x in range(n)])/n)**(1/2) 5 | print(std) 6 | -------------------------------------------------------------------------------- /Hackerank/Python/The Minion Game.py: -------------------------------------------------------------------------------- 1 | def minion_game(string): 2 | # your code goes here 3 | vowels_list = set(['a','e','i','o','u','A','E','I','O','U']) 4 | consonants = 0 5 | vowels = 0 6 | n = len(string) 7 | for i, l in enumerate(string): 8 | if l in vowels_list: 9 | vowels += n-i 10 | else: 11 | consonants += n-i 12 | if vowels == consonants: 13 | print ("Draw") 14 | elif vowels > consonants: 15 | print ("Kevin {}".format(vowels)) 16 | else: 17 | print ("Stuart {}".format(consonants)) 18 | -------------------------------------------------------------------------------- /Hackerank/Python/Weighted Mean.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | n = int(input()) 3 | arr = list(map(int, input().split())) 4 | weights = list(map(int, input().split())) 5 | print(round(sum([arr[x]*weights[x] for x in range(len(arr))]) / sum(weights), 1)) 6 | -------------------------------------------------------------------------------- /Hackerank/Python/Words Score.py: -------------------------------------------------------------------------------- 1 | def is_vowel(letter): 2 | return letter in ['a', 'e', 'i', 'o', 'u', 'y'] 3 | 4 | def score_words(words): 5 | score = 0 6 | for word in words: 7 | num_vowels = 0 8 | for letter in word: 9 | if is_vowel(letter): 10 | num_vowels += 1 11 | if num_vowels % 2 == 0: 12 | score += 2 13 | else: 14 | ++score 15 | return score 16 | -------------------------------------------------------------------------------- /Hackerank/Python/smartphone.py: -------------------------------------------------------------------------------- 1 | num = int(input()) 2 | suy = [] 3 | 4 | for i in range(num): 5 | suy.append(int(input())) 6 | 7 | suy.sort() 8 | 9 | for i in range(num): 10 | suy[i] = suy[i]*(num-i) 11 | 12 | print(max(suy)) 13 | -------------------------------------------------------------------------------- /Leetcode/C++/.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "windows-gcc-x64", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "compilerPath": "gcc", 9 | "cStandard": "${default}", 10 | "cppStandard": "${default}", 11 | "intelliSenseMode": "windows-gcc-x64", 12 | "compilerArgs": [ 13 | "-Wall", 14 | "-Wextra", 15 | "-Wpedantic" 16 | ] 17 | } 18 | ], 19 | "version": 4 20 | } -------------------------------------------------------------------------------- /Leetcode/C++/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "C/C++ Runner: Debug Session", 6 | "type": "cppdbg", 7 | "request": "launch", 8 | "args": [], 9 | "stopAtEntry": false, 10 | "cwd": "c:\\Users\\Lenovo\\Daily-Coding-DS-ALGO-Practice\\Leetcode\\C++", 11 | "environment": [], 12 | "program": "c:\\Users\\Lenovo\\Daily-Coding-DS-ALGO-Practice\\Leetcode\\C++\\build\\Debug\\outDebug", 13 | "internalConsoleOptions": "openOnSessionStart", 14 | "MIMode": "gdb", 15 | "miDebuggerPath": "gdb", 16 | "externalConsole": false 17 | } 18 | ] 19 | } -------------------------------------------------------------------------------- /Leetcode/C++/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp_Runner.warnings": [ 3 | "-Wall", 4 | "-Wextra", 5 | "-Wpedantic" 6 | ], 7 | "C_Cpp_Runner.compilerArgs": [], 8 | "C_Cpp_Runner.includePaths": [], 9 | "C_Cpp_Runner.linkerArgs": [], 10 | "C_Cpp_Runner.cStandard": "", 11 | "C_Cpp_Runner.cppStandard": "", 12 | "C_Cpp_Runner.excludeSearch": [], 13 | "C_Cpp_Runner.enableWarnings": true, 14 | "C_Cpp_Runner.warningsAsError": false 15 | } -------------------------------------------------------------------------------- /Leetcode/C++/First Missing Positive.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int firstMissingPositive(vector& nums) 6 | { 7 | int n = nums.size(); 8 | int j = 0; 9 | for(int i=0; i=1 && curr<=n && nums[curr-1]! = curr) 13 | { 14 | int temp = nums[curr-1]; 15 | nums[curr-1] = curr; 16 | curr = temp; 17 | } 18 | } 19 | for(int i=0; ia ={3,4,-1,1}; 30 | cout<>1; 10 | } 11 | return sum; // returning the value 12 | 13 | } 14 | }; -------------------------------------------------------------------------------- /Leetcode/C++/KthMissingPositiveNumber.cpp: -------------------------------------------------------------------------------- 1 | //Given an array arr of positive integers sorted in a strictly increasing order, and an integer k. 2 | 3 | //Find the kth positive integer that is missing from this array. 4 | 5 | //Input: arr = [2,3,4,7,11], k = 5 6 | //Output: 9 7 | //Explanation: The missing positive integers are [1,5,6,8,9,10,12,13,...]. The 5th missing positive integer is 9. 8 | //Example 2: 9 | 10 | //Input: arr = [1,2,3,4], k = 2 11 | //Output: 6 12 | //Explanation: The missing positive integers are [5,6,7,...]. The 2nd missing positive integer is 6. 13 | 14 | class Solution { 15 | public: 16 | int findKthPositive(vector& arr, int k) { 17 | 18 | for(int i=0;i& nums) { 9 | sort(nums.begin(),nums.end()); 10 | return nums[nums.size()/2]; 11 | } 12 | }; 13 | 14 | 15 | /* Test Cases 16 | Example 1: 17 | 18 | Input: nums = [3,2,3] 19 | Output: 3 20 | Example 2: 21 | 22 | Input: nums = [2,2,1,1,1,2,2] 23 | Output: 2 */ -------------------------------------------------------------------------------- /Leetcode/C++/Number of 1 bits.cpp: -------------------------------------------------------------------------------- 1 | //Link to the problem 2 | /* 3 | https://leetcode.com/problems/number-of-1-bits/ 4 | */ 5 | 6 | //According to the problem: 7 | 8 | //AIM: Return the number of '1' bits it has (also known as the Hamming weight). 9 | 10 | /* 11 | 12 | 13 | Example 1: 14 | 15 | Input: n = 00000000000000000000000000001011 16 | Output: 3 17 | Explanation: The input binary string 00000000000000000000000000001011 has a total of three '1' bits. 18 | 19 | */ 20 | //SOLUTION: 21 | 22 | class Solution { 23 | public: 24 | int hammingWeight(uint32_t n) { 25 | int x = 0; 26 | for(int i = 0; i<32; i++){//traversing the complete 32 bit integer 27 | if(n & 1 == 1)//if found 1 28 | x++;//add to sol 29 | n = n>>1;//check next bit 30 | } 31 | return x;//return total number of 1 bits. 32 | } 33 | }; -------------------------------------------------------------------------------- /Leetcode/C++/josephus_problem_recursion.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int josephus(int n, int k) 4 | { 5 | if(n==1) 6 | { 7 | return 1; 8 | } 9 | 10 | else 11 | { 12 | return (josephus(n-1,k) + k-1)%n +1; 13 | } 14 | } 15 | int main() 16 | { 17 | int t; 18 | 19 | cin>>t; 20 | 21 | while(t--) 22 | { 23 | int n; 24 | cin>>n; 25 | 26 | int k; 27 | 28 | cin>>k; 29 | 30 | cout< 2 | 3 | using namespace std; 4 | 5 | class Solution { 6 | public: 7 | string breakPalindrome(string palindrome) 8 | { 9 | string hack; 10 | if(palindrome.length()==1) 11 | return hack; 12 | for(int i=0;i 2 | 3 | int factorial(int n) { 4 | int f; 5 | 6 | for(f = 1; n > 1; n--) 7 | f *= n; 8 | 9 | return f; 10 | } 11 | 12 | int ncr(int n,int r) { 13 | return factorial(n) / ( factorial(n-r) * factorial(r) ); 14 | } 15 | 16 | int main() { 17 | int n, i, j; 18 | 19 | n = 5; 20 | 21 | for(i = 0; i <= n; i++) { 22 | for(j = 0; j <= n-i; j++) 23 | printf(" "); 24 | 25 | for(j = 0; j <= i; j++) 26 | printf(" %3d", ncr(i, j)); 27 | 28 | printf("\n"); 29 | } 30 | return 0; 31 | } 32 | 33 | /** Output 34 | 1 35 | 1 1 36 | 1 2 1 37 | 1 3 3 1 38 | 1 4 6 4 1 39 | 1 5 10 10 5 1 40 | -------------------------------------------------------------------------------- /Leetcode/Check if Sentence is Pangram.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | string s; 7 | getline(cin, s); 8 | int n=s.length(); 9 | int freq[26]; 10 | memset(freq,0,sizeof(freq)); 11 | for(int i=0;i midWeight) { 15 | need += 1; 16 | curr = 0; 17 | } 18 | curr += weight; 19 | } 20 | if (need > D) { 21 | maxWeight = midWeight + 1; 22 | } 23 | else { 24 | totalWeight = midWeight; 25 | } 26 | } 27 | return maxWeight; 28 | } 29 | } -------------------------------------------------------------------------------- /Leetcode/Java/Hamming.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class Hamming 3 | { 4 | static int hammingDistance(int x, int y) 5 | { 6 | int n = x ^ y; 7 | int setBits = 0; 8 | 9 | while (n > 0) 10 | { 11 | setBits += n & 1; 12 | n >>= 1; 13 | } 14 | 15 | return setBits; 16 | } 17 | public static void main(String[] args) 18 | { 19 | Scanner sc = new Scanner(System.in); 20 | int x = sc.nextInt(); 21 | int y = sc.nextInt(); 22 | System.out.println(hammingDistance(x, y)); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /Leetcode/Java/Longest_valid_parenthesis.java: -------------------------------------------------------------------------------- 1 | class Longest_valid_parenthesis{ 2 | public int longestValidParentheses(String s) { 3 | int n = s.length(); 4 | int[] dp = new int[n]; 5 | int max = 0; 6 | for (int i = 1; i < s.length(); i++){ 7 | if (s.charAt(i) == ')' && s.charAt(i-1) == '('){ 8 | dp[i] = (i >= 2 ? dp[i-2] : 0)+2; 9 | } else if (s.charAt(i) == ')' && s.charAt(i-1) == ')'){ 10 | if (i-dp[i-1] > 0 && s.charAt(i-dp[i-1]-1) == '('){ 11 | dp[i] = dp[i-1] + (i-dp[i-1] >= 2 ? dp[i-dp[i-1]-2] : 0) + 2; 12 | } 13 | } 14 | max = Math.max(max, dp[i]); 15 | } 16 | return max; 17 | } 18 | } -------------------------------------------------------------------------------- /Leetcode/Java/Min_No_Of_Refueling_Stops.java: -------------------------------------------------------------------------------- 1 | class Min_No_Of_Refueling_Stops{ 2 | public int minRefuelStops(int target, int startFuel, int[][] stations) { 3 | int n = stations.length; 4 | long[] dp = new long[n+1]; 5 | dp[0] = startFuel; 6 | for (int i = 0; i < n; i++){ 7 | for (int t = i; t >= 0; t--){ 8 | if (dp[t] >= stations[i][0]){ 9 | dp[t+1] = Math.max(dp[t+1], dp[t]+(long)stations[i][1]); 10 | } 11 | } 12 | } 13 | for (int i = 0; i <= n; i++){ 14 | if (dp[i] >= target) return i; 15 | } 16 | return -1; 17 | } 18 | } -------------------------------------------------------------------------------- /Leetcode/Java/Number of 1 Bits.java: -------------------------------------------------------------------------------- 1 | // Question https://leetcode.com/problems/number-of-1-bits/ 2 | 3 | // Solution 4 | import java.util.Scanner; 5 | 6 | class main { 7 | public static int bits(int n) { 8 | int count = 0; 9 | while (n != 0) { 10 | count += (n & 1); 11 | n >>>= 1; 12 | } 13 | return count; 14 | } 15 | 16 | public static void main(String[] args) { 17 | Scanner sc = new Scanner(System.in); 18 | System.out.print("Enter number : "); 19 | int n = sc.nextInt(); 20 | System.out.println(bits(n)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Leetcode/Java/StockProblem.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | import java.io.*; 3 | 4 | class StockProblem 5 | { 6 | public static void main (String[] args) throws IOException 7 | { 8 | Scanner sc = new Scanner(System.in); 9 | int n = sc.nextInt(); 10 | int prices[] = new int[n]; 11 | for(int i=0;i x: 24 | diff = x 25 | minval = i 26 | 27 | # Print the answer 28 | print(minval) -------------------------------------------------------------------------------- /Leetcode/Python/StringtoInteger.py: -------------------------------------------------------------------------------- 1 | def myAtoi(string): 2 | result = 0 3 | sign = 1 4 | i = 0 5 | if string[0] == '-': 6 | sign = -1 7 | i += 1 8 | for j in range(i,len(string)): 9 | result = result*10+(ord(string[j])-ord('0')) 10 | return sign * result 11 | string =input("Enter string") 12 | print (myAtoi(string)) 13 | """ 14 | Testcase-1: 15 | Enter String: "-8479" 16 | Output: -8479 17 | 18 | Testcase-2: 19 | Enter String:"124" 20 | Output: 124 21 | 22 | TimeComplexity:O(n) 23 | Space complexity:O(1) 24 | """ -------------------------------------------------------------------------------- /Leetcode/Python/Valid_Mountain_Problem.py: -------------------------------------------------------------------------------- 1 | def Valid_Mount(arr:list[int]): 2 | if len(arr) < 3 : 3 | return False 4 | else : 5 | for i in range(0, len(arr)-1 ): 6 | if arr[i+1] > arr[i] : 7 | continue 8 | else : 9 | break 10 | for j in range(i , len(arr)-1 ) : 11 | if arr[j+1] < arr[j] : 12 | continue 13 | else : 14 | return False 15 | 16 | return True 17 | 18 | if __name__ == "__main__": 19 | x = Valid_Mount([1,2,3,4,5,5]) 20 | print(x) 21 | 22 | 23 | #Input = [1,2,3,4,4*(-1)] 24 | #Output = True 25 | #Input = [1,2,3,4,5,5] 26 | #Output = False 27 | #Input = [1,2,3,4,5,4] 28 | #Output = True 29 | #Input = [1,3,2,6,4,7] 30 | #Output = False -------------------------------------------------------------------------------- /Leetcode/Python/multiplyStrings.py: -------------------------------------------------------------------------------- 1 | #Problem link : https://leetcode.com/problems/multiply-strings/ 2 | def multiply(num1, num2): 3 | return str(int(num1)*int(num2)) 4 | 5 | 6 | num1,num2 = input().split(); 7 | print(multiply(num1,num2)) 8 | 9 | #Example test case 10 | # Input : "2" "3" 11 | # Output : "6" 12 | -------------------------------------------------------------------------------- /Leetcode/Python/reverseInteger.py: -------------------------------------------------------------------------------- 1 | 2 | #Problem link : https://leetcode.com/problems/reverse-integer/ 3 | def reverse(x): 4 | s = str(abs(x)) 5 | ans = int (s[::-1]) 6 | if (ans > (pow(2,31)-1) or ans < pow(2,-31)): 7 | return 0 8 | elif (x >= 0): 9 | return ans 10 | return ans - 2*ans 11 | 12 | 13 | 14 | 15 | num = int(input()) 16 | print(reverse(num)) 17 | 18 | #Example test case 19 | # Input : 123 20 | # Output : 321 21 | # Input : - 123 22 | # Output : -321 23 | -------------------------------------------------------------------------------- /Leetcode/check-if-the-sentence-is-pangram.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Main { 4 | public static void main(String[] args){ 5 | Scanner sc = new Scanner(System.in); 6 | String s = sc.next(); 7 | System.out.println(checkIfPangram(s)); 8 | } 9 | 10 | public boolean checkIfPangram(String sentence) { 11 | Map map = new HashMap(); 12 | 13 | String alph = "abcdefghijklmnopqrstuvwxyz"; 14 | for (int i = 0 ; i < alph.length(); i++){ 15 | if(!sentence.contains(alph.substring(i,i+1))){ 16 | return false; 17 | } 18 | } 19 | return true; 20 | 21 | } 22 | } 23 | 24 | // Example test cases 25 | // 26 | // Input: sentence = "thequickbrownfoxjumpsoverthelazydog" 27 | // Output: true 28 | // 29 | // Input: sentence = "leetcode" 30 | // Output: false 31 | -------------------------------------------------------------------------------- /Leetcode/firstunquiecharacter.java: -------------------------------------------------------------------------------- 1 | package Leetcode; 2 | 3 | import java.util.*; 4 | public class firstunquiecharacter { 5 | public int firstUniqChar() { 6 | Scanner sc=new Scanner(System.in); 7 | System.out.println("enter the word in which you have to find the unquie char"); 8 | String s=sc.nextLine(); 9 | HashMap map = new HashMap(); 10 | for(int i = 0; i 2 | #include 3 | 4 | int last_index(int arr[],int size,int x){ 5 | if(size<1){ 6 | return -1; 7 | } 8 | size--; 9 | if(arr[size]==x) 10 | { 11 | return size; 12 | } 13 | return last_index(arr,size,x); 14 | } 15 | int main(){ 16 | int N,x,i,index; 17 | printf("Enter the size of array:"); 18 | scanf("%d",&N); 19 | int arr[N]; 20 | printf("Enter the elements of array:"); 21 | for(i=0;i (name of File problem_name example reverse_string) 8 | 9 | With the Following Data : 10 | 11 | a. Question 12 | b. Sample Input 13 | c. Sample OutPut 14 | d. Programming language Used 15 | e. Solution Explanation - Optional 16 | 17 | 2. Solution -> (name of File problem_name_solution.extension example reverse_string_solution.java) 18 | 19 | 3. Test Cases (Optional) 20 | -------------------------------------------------------------------------------- /Miscellaneous problems/arraysorting/sort_arr.c: -------------------------------------------------------------------------------- 1 | /*Given an array A[] consisting 0s, 1s and 2s. The task is to write a function that sorts the given array. The functions should put all 0s first, then all 1s and all 2s in last.*/ 2 | 3 | #include 4 | #include 5 | int main(){ 6 | int N,temp,i,j; 7 | printf("Enter the size of array:"); 8 | scanf("%d",&N); 9 | int arr[N]; 10 | printf("Enter the array containing 0,1 & 2 only:"); 11 | for(i=0;i