├── .gitignore ├── .idea ├── .gitignore ├── Data-Structure-Algorithms.iml ├── inspectionProfiles │ ├── Project_Default.xml │ └── profiles_settings.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── .vscode └── settings.json ├── Algorithms CPP ├── 2D arrays │ ├── 2dArrayIntro.cpp │ ├── Array waveform.cpp │ ├── Majority Element.cpp │ ├── Minimum Platform.cpp │ ├── Search2DMatrix1.java │ ├── Search2DMatrix2.java │ ├── Smallest positive missing.cpp │ ├── SpiralPrint.java │ ├── Trappinf rainwater.cpp │ ├── WavePrint.java │ ├── search2DMatrix1.cpp │ ├── search2DMatrix2.cpp │ ├── spiralPrint.cpp │ └── wavePrint.cpp ├── Array Left Rotation.cpp ├── Array Right Rotation.cpp ├── BFS graph.cpp ├── BST.cpp ├── BinarySearch.cpp ├── BinaryTree_AllNodesSum.cpp ├── BinaryTree_LevelOrderTraversal.cpp ├── BinaryTree_ReverseLevelOrder.cpp ├── BinaryTree_SpiralLevelOrderTraversal.cpp ├── BinaryTree_VerticalSum.cpp ├── Bubble Sort using Recursion.cpp ├── Bubble_sort.c ├── BucketSort.c ├── BucketSort.cpp ├── C. Delete Two Elements.cpp ├── Circular Linked List.cpp ├── Circular Queue Using Array.cpp ├── Counter_Clockwise_rotate_LL.cpp ├── CountingSort.cpp ├── Create Create Fitting The Array.cpp ├── Create Fitting The Array.cpp ├── DAM OF CANDIES.cpp ├── DFS ├── Detect_Remove_loop_in_LL.cpp ├── Dijkstra's Algorithm.cpp ├── Dutch_National_Flag_sort.cpp ├── Edit Distance.cpp ├── ExponentialSearch.cpp ├── Flatten the linked list.cpp ├── Graph │ ├── Clone a graph.cpp │ ├── Create and print graph.cpp │ ├── Detect cycle in directed graph using DFS & BFS.cpp │ ├── Detect cycle in undirected graph using DFS & BFS.cpp │ ├── Flood fill algo.cpp │ ├── Implement BFS algorithm.cpp │ ├── Implement DFS algorithm.cpp │ ├── Making wired connections.cpp │ ├── Minimum step by knight.cpp │ └── Search in maze.cpp ├── Greedy.cpp ├── Group Anagrams.cpp ├── Heap │ ├── Maxheap minheap using array and recursion.cpp │ ├── Maximum of all subarray of size K.cpp │ ├── Merge K sorted linklist.cpp │ ├── Merge k sorted array.cpp │ ├── Merge two binary maxheaps.cpp │ ├── Reorganize strings.cpp │ ├── Sort array using heap HEAPSORT.cpp │ ├── kth largest element in array.cpp │ ├── kth largest sum continuous subarrays.cpp │ └── kth smallest and kth largest in unsorted array.cpp ├── Inorder_successor_BT.cpp ├── Inorder_without_recursion_BT.cpp ├── Insertion Sort using Recursion.cpp ├── Intersection Point in Y Shapped Linked Lists.cpp ├── Intersection_of_2_arrays.cpp ├── JumpSearch.cpp ├── KClosestPointstoOrigin.cpp ├── KMP_Algorithm.cpp ├── Kadane's Algorithm ├── Kadane's Algorithm.cpp ├── LCS.cpp ├── Linked List │ ├── Doubly Linked List │ │ ├── DLL.cpp │ │ ├── Header_DoubleLL.h │ │ └── ReverseDoublyList.cpp │ └── Singly Linked List │ │ ├── DetectAndRemoveLoopInLL.cpp │ │ ├── Intersection of two sorted linked lists │ │ ├── MiddleOfLinkedList.cpp │ │ ├── ReverseLinkedList.cpp │ │ ├── SinglyLinkedList.cpp │ │ ├── detectCycle.cpp │ │ └── reverseLLinGroup.cpp ├── LongestPalindromeInAString.cpp ├── MCM.cpp ├── Maximum of all subarray of size K.cpp ├── MergeWithoutExtraSpace copy.cpp ├── MergeWithoutExtraSpace.cpp ├── Min no of fountain to cover garden.cpp ├── MinimumPlatforms.cpp ├── NthPrime.cpp ├── Prim's Algorithm.cpp ├── Queue │ ├── KQueue.cpp │ ├── circularQueue.cpp │ ├── circularTour.cpp │ ├── deque.cpp │ ├── implementQueue.cpp │ ├── negativeInteger.cpp │ ├── nonRepeating.cpp │ ├── queueIntro.cpp │ ├── reverseFirstK.cpp │ ├── reverseQueue.cpp │ └── sumMaxMin.cpp ├── QuickSort.cpp ├── Quick_Sort_using_Recursion.cpp ├── Radix_Sort.cpp ├── RainWaterTrapping.cpp ├── Rat in a Maze.cpp ├── Recover Binary Search Tree.cpp ├── RedBlackTree.cpp ├── Reverse a Linked List using Recusion.cpp ├── Reverse a linked list.cpp ├── RodCutting.cpp ├── Scrambled_String.cpp ├── Selection Sort using Recursion.cpp ├── Sentinal_search.py ├── Stack │ ├── Applications │ │ ├── Evaluation-Prefix-Postfix(stack).cpp │ │ ├── Reverse_Function(linklist).cpp │ │ ├── Reverse_Function(stack).cpp │ │ └── balacing paraenthesis(stack).cpp │ ├── Stack( with linked-list).cpp │ ├── Stack(with array).cpp │ ├── bracketReversals.cpp │ ├── deleteMiddle.cpp │ ├── deleteMiddleElementStack.cpp │ ├── insertAtBottom.cpp │ ├── nextgreatestelement.cpp │ ├── redundantBrackets.cpp │ ├── reverseString.cpp │ ├── sortStack.cpp │ ├── stackusingll.cpp │ ├── twoStack.cpp │ └── validBrackets.cpp ├── Strings │ ├── Finding_Duplicates_In_A_String.c │ └── autoPasswordGenerator.cpp ├── SubarrayWithGivenSum.cpp ├── Swap_2nodes_without_dataswap.cpp ├── Tower Of Hanoi.cpp ├── TowerOfHanoi.cpp ├── TravellingSalesmanProblem ├── Union_of_2_arrays.cpp ├── Unique Binary Search Trees.cpp ├── armstrong.cpp ├── bellmen_ford.cpp ├── binary_search_tree.cpp ├── bubble-sort.cpp ├── bubble_sort.cpp ├── bubblesort.cpp ├── count occurrences of anagrams.cpp ├── cycle_detection_undirected_graph.cpp ├── deleting_element.c++ ├── djkstra.cpp ├── dynamicLinearSearch.cpp ├── flattenAbinaryTree.cpp ├── frequency_of_chars.cpp ├── gcd_recursive.cpp ├── groups.cpp ├── hashing.cpp ├── heap_sort copy.cpp ├── heap_sort.cpp ├── infix_postfix_conversion.c ├── insertion-sort.cpp ├── insertion_sort.cpp ├── kadane.cpp ├── knapsack.c ├── knight-tour-implementation.cpp ├── longest common subsequence in 2 strings (dp problem).cpp ├── max_difference.cpp ├── merge_common_linked_list.c ├── mergesort.cpp ├── multiply_two_matrices.cpp ├── nextPermutation.java ├── nthNode_Inorder_BT.cpp ├── pattern.cpp ├── permutations_backtracking.cpp ├── prime-funct.cpp ├── print_all_combination_of_string.cpp ├── print_all_permutation_of_string.cpp ├── priority_queue.cpp ├── queue using arrray.cpp ├── queue using linkedlist.cpp ├── queue_arr.cpp ├── reverse linkedlist.cpp ├── reverse-array.cpp ├── reverse.cpp ├── reversewordwise.cpp ├── selectionSort.cpp ├── selection_sort.cpp ├── shell sort.cpp ├── sieve_algorithm.cpp ├── simpleCalculator.cpp ├── slidingWindow.cpp ├── sort_bubble.dart ├── sorting.cpp ├── spiralprint.cpp ├── stack using linkedlist.cpp ├── sum-even-odd.cpp ├── sumoftwoarrays.cpp ├── ternary_search.py ├── topological_sort.cpp ├── training session.cpp ├── unionOfArrays.cpp ├── vertical traversal in tree .cpp ├── z_function.cpp └── zigzagTraversalOfBinaryTree.cpp ├── Algorithms in C# ├── BFS.cs ├── Bellman-Ford-Algorithm.cs ├── DFS.cs ├── Dijkstra-Algorithm.cs ├── Floyd-Warshall-Algorithm.cs └── Greedy-Algorithm.cs ├── Algorithms in Java ├── HelloWorld.java └── stdInOut.java ├── Algorithms in Operating Systems ├── CPU Scheduling Algorithms │ ├── Banker's Algorithm.c │ ├── FCFS Algorithm.c │ ├── Non-Primitive Priority Scheduling Algorithm.c │ └── SJF Algorithm.c └── Memory Allocation Algorithms │ ├── Best Fit Algorithm.c │ └── First Fit Algorithm.c ├── Array_Rotation.cpp ├── Binary Search Tree ├── BinarySearchTree$Node.class ├── BinarySearchTree.class └── BinarySearchTree.java ├── Binary_Tree_Using_Python ├── Depth_of_BT.py ├── check_both_tree_is_same.py ├── dfs_traversals_BT.py ├── find_leaf_node_of_BT.py ├── invert_a_BT.py ├── leaf_similar_tree.py ├── left_view_of_Bt.py ├── no_of_node_in_BT.py ├── path_sum_compare_with__target_sum.py ├── path_sum_of_BT.py ├── print_all_nodes_dont_have_siblings.py ├── sum_of_left_leaf_node.py ├── sum_of_root_to_leaf_paths.py └── univalued_BT.py ├── CSES Problem Set ├── Building Roads.cpp ├── Dynamic Programming │ ├── 0-1 Knapsack Problem.cpp │ ├── Array Description.cpp │ ├── BookShop.cpp │ ├── Coin Combinations I.cpp │ ├── Coin Combinations II.cpp │ ├── Counting_Numbers_yogmanamit.cpp │ ├── Counting_Tilings_yogmanamit.cpp │ ├── Dice Combinations.cpp │ ├── Edit Distance.cpp │ ├── Grid Paths.cpp │ ├── Increasing Subsequence.cpp │ ├── Longest Common Subsequence.cpp │ ├── Minimizing Coins.cpp │ ├── Money Sums.cpp │ ├── Projects.cpp │ ├── Rectangle Cutting.cpp │ ├── Removal Game.cpp │ ├── Removing Digits.cpp │ ├── Two Sets II.cpp │ ├── dicecombinationsyogmanamit.cpp │ └── jumpgame_yogmanamit.cpp ├── Graph │ ├── Building Roads.cpp │ ├── Building Teams.cpp │ ├── Counting Rooms.cpp │ ├── Course Schedule.cpp │ ├── Cycle Finding.cpp │ ├── Download Speed.cpp │ ├── Flight Discount.cpp │ ├── Flight Routes Check.cpp │ ├── Flight Routes.cpp │ ├── Game Routes.cpp │ ├── High Score.cpp │ ├── Investigation.cpp │ ├── Knight's Tour.cpp │ ├── Labyrinth.cpp │ ├── Longest Flight Route.cpp │ ├── Mail Delivery.cpp │ ├── Message Route.cpp │ ├── Monsters.cpp │ ├── Planet Queries I.cpp │ ├── Planets and Kingdoms.cpp │ ├── Road Construction.cpp │ ├── Road Reparation.cpp │ ├── Round Trip II.cpp │ ├── Round Trip.cpp │ ├── Shortest Routes I.cpp │ ├── Shortest Routes II.cpp │ └── download.cpp ├── Increasing_Array.cpp ├── Message Route.cpp ├── Round Trip.cpp ├── Searching and Sorting │ ├── Playlist.cpp │ ├── Towers.cpp │ └── apartments.cpp ├── Shortest Routes I.cpp ├── Shortest Routes II.cpp ├── Subordinates.cpp ├── Subtree Queries.cpp ├── countinggridsAmitkumar9199.cpp ├── monsters.cpp ├── rangexorqueries.cpp └── tree queries amitkumar9199.cpp ├── Codeforces Problems ├── 110A - Nearly Lucky Number.cpp ├── 112A - Petya and Strings.cpp ├── 116A - Tram.cpp ├── 116A.cpp ├── 118A.cpp ├── 122A.cpp ├── 136A - Presents.cpp ├── 141A - Amusing Joke.cpp ├── 1420C1 Pokemon Army(easy).cpp ├── 1420C2 - Pokemon Army(hard).cpp ├── 1426A - Floor Number.cpp ├── 144A - Arrival of the General.cpp ├── 1454A - Special Permutation.cpp ├── 1487A - Arena.cpp ├── 148A - Insomnia cure.cpp ├── 1506A - Strange Table.cpp ├── 1519A - Red and Blue Beans.cpp ├── 1520B - Ordinary Numbers.cpp ├── 1542A - Odd Set.cpp ├── 1549C.cpp ├── 1553A - Digits Sum.cpp ├── 155A - I_love_%username%.cpp ├── 1560B - Who's Opposite.cpp ├── 1562D1.cpp ├── 158A - Next Round.cpp ├── 158A.cpp ├── 1593A - Elections.cpp ├── 1594A.cpp ├── 1594B.cpp ├── 1598C.cpp ├── 1624A - Plus One on the Subset.cpp ├── 1626A - Equidistant Letters.cpp ├── 1650A - Deletions of Two Adjacent Letters.cpp ├── 1660B - Vlad and Candies.cpp ├── 1676A - Lucky.cpp ├── 1692A - Marathon.cpp ├── 1698A - XOR Mixup.cpp ├── 1703A - YES or YES.cpp ├── 1703B - ICPC Balloons.cpp ├── 1703C - Cypher.cpp ├── 1708C - Doremy's IQ.cpp ├── 1709C - Recover an RBS.cpp ├── 1721A.py ├── 1721C - MinMax Array Transformation.cpp ├── 200B - Drinks.cpp ├── 228A - Is your horseshoe on the other hoof.cpp ├── 231A - Team.cpp ├── 233A - Perfect Permutation.cpp ├── 236A - Boy or Girl.cpp ├── 263A - Beautiful Matrix.cpp ├── 282A.cpp ├── 427A - Police Recruits.cpp ├── 443A - Anton and Letters.cpp ├── 467A - George and Accommodation.cpp ├── 4A - Watermelon.cpp ├── 50A - Domino piling.cpp ├── 50A.cpp ├── 510A - Fox And Snake.cpp ├── 540A - Combination Lock.cpp ├── 546A - Soldier and Bananas.cpp ├── 599A - Patrick and Shopping.cpp ├── 59A - Word.cpp ├── 617A - Elephant.cpp ├── 61A - Ultra-Fast Mathematician.cpp ├── 677A - Vanya and Fence.cpp ├── 705A - Hulk.cpp ├── 719E-Arranging The Sheep.py ├── 71A - Way Too Long Words.cpp ├── 723A - The New Year Meeting Friends.cpp ├── 732A - Buy a Shovel.cpp ├── 734A - Anton and Danik.cpp ├── 749A - Bachgold Problem.cpp ├── 750A - New Year and Hurry.cpp ├── 785A - Anton and Polyhedrons.cpp ├── 791A - Bear and Big Brother.cpp ├── 935A - Fafa and his Company.cpp ├── 977A - Wrong Subtraction.cpp ├── A. Windblume Ode.cpp ├── EVMHACK@codechef.cpp ├── Mainak and Array.cpp ├── TRISQ.cpp ├── allaresame.cpp ├── code.cpp ├── color.cpp ├── color2.cpp ├── color3.cpp ├── divisible_numbers.cpp ├── fish.cpp ├── number_game.cpp ├── pizzaForces.cpp ├── save_magazine.cpp ├── sort_zero.cpp ├── sum game.cpp └── twoTables.cpp ├── CompositeAndPrime.cpp ├── Create Maximum sum of a path in a Right Number Triangle in cpp ├── CustomHashFunction.cpp ├── Divide Array into Equal Pairs ├── Find number of endless points in cpp ├── First Missing Positive ├── First_Missing_Positive.py ├── Floyd_Triangle.cpp ├── GFG ├── Book_Allocation.java ├── FlatteningLL.cpp ├── Kadanes_Algorithm.cpp ├── Max_Circular_Subarray_Sum.cpp ├── Minimum_Bit_Flips.cpp ├── NoOfCoins.cpp ├── Trapping_Rainwater.cpp ├── coinchange.cpp └── stockBuySell.cpp ├── Go └── Data-Structures │ ├── Binary-Search-Tree │ └── main.go │ ├── Hash-Table │ └── main.go │ └── Single-Linked-List │ └── main.go ├── Google Kickstart 2022 Round G Walktober.py ├── Graphs questions from Love Babbar SDE sheet ├── BFS.cpp ├── BFS.exe ├── Creating_And_displaying_a_graph.cpp ├── Creating_And_displaying_a_graph.exe ├── Cycle_Detection_in_undirected_graph_BFS.cpp ├── Cycle_Detection_in_undirected_graph_BFS.exe ├── Cycle_Detection_in_undirected_graph_DFS.cpp ├── Cycle_Detection_in_undirected_graph_DFS.exe ├── Cycle_detection_in_Directed_graph_DFS.cpp ├── Cycle_detection_in_Directed_graph_DFS.exe ├── Cycle_detection_in_directed_graph_BFS.cpp ├── Cycle_detection_in_directed_graph_BFS.exe ├── DFS.cpp ├── DFS.exe ├── Search_in_a_maze.cpp ├── Topological_Sort_DFS.cpp ├── Topological_Sort_DFS.exe ├── Topological_sort_BFS.cpp └── Topological_sort_BFS.exe ├── Iterative Fast Fourier Transformation for polynomial multiplication ├── Job_scheduling.cpp ├── Jump Game ├── Kruskal.cpp ├── Lcs.cpp ├── Leetcode Easy ├── BuySellStock.java ├── ContainsDuplicate.java ├── Diameter_Of_Binary_Tree.py ├── Divide_Array_Into_Equal_Pairs.java ├── EditDistance.cpp ├── HappyNumber.java ├── InvertedBinaryTree.cpp ├── Leetcode.java ├── Longest Common Prefix ├── LongestCommonPrefix.java ├── Maximum Depth of Binary Tree.cpp ├── Merge two sorted lists.cpp ├── Middle of the Linked List.cpp ├── Palindrome Linked List.cpp ├── Powe Of Three.cpp ├── RemoveElement.cpp ├── RomanToInteger.java ├── Set Mismatch.py ├── SingleNumber.java ├── Square Root Rounded to Nearest Integer ├── Symmetric_tree.c ├── TwoSum.cpp ├── magic_chessboard.cpp ├── reverse_linked_list.cpp └── twosum.java ├── Leetcode Problems ├── 136. Single Number.java ├── 39.Combination_sum.cpp ├── 3SUM.cpp ├── 3Sum Closest ├── 3sum_Closest.cpp ├── 4SUM.cpp ├── 4sum.py ├── 51. N-Queens ├── 75. Sort_color.cpp ├── 91. Decode_ways.cpp ├── AddBinary.cpp ├── AddTwoLinkedList.cpp ├── Binary-Search704.java ├── ClimbingStairs.cpp ├── Count ans Say.cpp ├── Divide Intervals Into Minimum Number of Groups.cpp ├── Find First and Last Position of Element in Sorted Array.cpp ├── Find the Duplicate Number ├── Find_the_Index_of_the_First_Occurrence_in_a_String.py ├── FirstMissingPositive.cpp ├── HighestMountainInArray.cpp ├── IntegerToRoman.cpp ├── Jump Game ├── LFU-Cache.cpp ├── LRU-Cache.cpp ├── Letter_Combinations_of_a_PhoneNumber.cpp ├── Longest Palindromic Substring.cpp ├── Longest Repeating Character Replacement.cpp ├── LongestRepeatingSubsequence.cpp ├── Longest_palindromic_substring.java ├── Max Area Island ├── MaximumProductSubarrayLeetcode.java ├── Median_of_two_sorted_array.c ├── MinStack.cpp ├── MinimuTimeToMakeRopeColorfull.cpp ├── MoveZeros.cpp ├── Multiply_Strings.py ├── N-Queens.cpp ├── NextPermutation.cpp ├── Non-overlapping Intervals.cpp ├── NumOfLIS.cpp ├── Optimal Partition of String.cpp ├── PartitionProblemDP.java ├── Partitioning Into Minimum Number Of Deci-Binary Numbers.cpp ├── Qns on BST ├── Rotate matrix by 90 degree ├── RotateList.cpp ├── Rotate_list.c ├── Running sum of 1d array.c ├── Search in Rotated Sorted Array.cpp ├── SingleNumber3.cpp ├── SlidingWindowMaximum.cpp ├── Strictly Palindromic Number.cpp ├── StringToInteger.cpp ├── SubarraySumEqualsK.java ├── Subrectangle_Queries.cpp ├── Sudoku_solver.cpp ├── SumofLeftLeaves.cpp ├── Trapping_rain_water.cpp ├── TwoInputSum2.cpp ├── TwoSum.java ├── TwoSumHashMap.java ├── ZigZagConversion.java ├── clone-graph.py ├── container_with_most_water.cpp ├── containerwithMostWater.cpp ├── dungeon_game.cpp ├── generate_parenthesis.cpp ├── house_robber.cpp ├── house_robber_2.cpp ├── house_robber_3.cpp ├── largest_rectangle_in_histogram.cpp ├── lastStoneWeight.cpp ├── list_cycle.cpp ├── longest_common_subsequence.cpp ├── longest_increasing_subsequence.cpp ├── matrix_transpose.cpp ├── maximumsubarray.cpp ├── medium │ ├── 12 Integer to Roman.py │ ├── 17. Letter Combinations of a Phone Number.py │ ├── 25. Reverse Nodes in k-Group.py │ ├── 43. Multiply Strings.cpp │ ├── 692 Top K Frequent Words.py │ ├── 76.Minimum Window Substring.py │ ├── 8.String to Integer (atoi).py │ ├── House_Robber.cpp │ ├── IncreasingTripletSequence.java │ ├── Jump Game II.py │ ├── JumpGame2.cpp │ ├── Remove_Nth_Node_From_End_of_List.c │ ├── SetMatrixZero.cpp │ ├── Swap_nodes_in_pairs.c │ ├── UniquePathsII.cpp │ ├── course-schedule.py │ ├── image Overlap.py │ ├── jump-game.py │ ├── lettercombinationofaPhoneNumber.cpp │ ├── longestPalindromeSubstring.cpp │ ├── minimum-path-sum.py │ ├── palindrome-partitioning.py │ ├── reverseInteger.java │ ├── unique-binary-search-trees.py │ └── zigzag-conversion.py ├── minDelSum.py ├── missingpositiveno.cpp ├── palindromeNumber.cpp ├── print_keypad_combinations.cpp ├── rain_trapping_problem.cpp ├── rain_water_trapped.cpp ├── removeduplicatesfromasortedarray.cpp ├── reverseInteger.cpp ├── reverse_linked_list.cpp ├── searchinsertposition.cpp ├── stock_buy_and_sell.cpp ├── stockyBuySell.cpp ├── sudoku.java ├── twoSum.cpp ├── valid_parentheseis_in_java.class ├── valid_parentheseis_in_java.java └── validparenthesis.cpp ├── Lis.cpp ├── MajorityElement.cpp ├── Maximum number of segments of lengths a, b and c in cpp ├── Maximum path sum for each position with jumps under divisibility condition in cpp ├── Minimum Bit Flips to Convert Number ├── N- Queen.cpp ├── Odd Even Linkedlist ├── PrepBytes_CP Problems ├── BoxesandToys.cpp ├── Denomination(Arrays).cpp ├── PerfectNumberandDivisors.cpp ├── ReversetheNumberUsingRecursion.cpp ├── TableChair(Recursion).cpp ├── Vpattern.cpp └── minandMax.cpp ├── Problems Java ├── ColoumnSum.java ├── CyclicSort.java ├── EuclideanAlgorithm.java ├── InsertionSort.java ├── LongestCommonSubsequence.java ├── MergeSorting.java ├── Olympics.java ├── PermuteString.java ├── SpiralMatrix.java ├── TopologicalSorting.java ├── lexicographic strings └── maxnumberInString.java ├── Problems Python ├── Knapsack.py ├── balanced_parantheses.py ├── bitonic.py ├── doraeomon.py ├── factorial.py ├── factors.py ├── gcd_lcm.py ├── guesser.py ├── lucky_four.py ├── merge_sort.s ├── pikachu.py ├── population_std.py ├── population_variance.py ├── remove_char.py ├── sum_of_integers ├── threeboxes.py └── treasure_hunt.py ├── Queue using Stacks.cpp ├── Queue_using_single_Stack.cpp ├── README.md ├── Random Problems ├── Doubly Linked List from a string ├── Josephus_problem.cpp ├── ODD_EVEN_GAME ├── Right view of binary tree.cpp ├── SquareRoot.cpp ├── a basic memory allocator and garbage collector using doubly linked list ├── diagonal diff.cpp ├── efficiently represent a sparse matrix ├── omkar and heavenly tree.cpp ├── readme.md ├── stack_in_dart.dart └── twosum.py ├── ReverseLinkedList.cpp ├── Shortest Distance in a Binary Maze.cpp ├── Strings ├── highest_occuring_character.cpp └── remove_consecutive_duplicates.cpp ├── Swap nodes in a linked list without swapping data ├── Swift ├── Linked-List │ ├── DoubleLinkedList.swift │ └── SingleLinkedList.swift ├── Queue │ └── Queue.swift └── Stack │ └── Stack.swift ├── Tic_Tac_Toe.cpp ├── Tower of Hanoi using recursion (C++ program) ├── TowerOfHanoi.cpp ├── Trapping rainwater problem ├── codechef problems ├── ANDSUBAR.cpp ├── ARRCONS.cpp ├── April Long One 2022(APRIL221D ) │ └── Dazzling_AXNODR_Challenge.cpp ├── August Long One 2022 (AUG221B) │ ├── HLEQN.cpp │ ├── SMALLXOR.cpp │ └── TWOTRAINS.cpp ├── BINARYSUB.cpp ├── CHFINVNT.cpp ├── COVIN.cpp ├── DIRECTN.cpp ├── DPOLY.cpp ├── DRAG.cpp ├── DSAPREP_01 - Basic Programming - Easy │ ├── EMPR.cpp │ ├── EXPRESSION_3.cpp │ ├── KNGATK.cpp │ ├── LUCNUM.cpp │ └── MONSTER1.cpp ├── DSAPREP_08 - Linked List │ ├── LLMID.cpp │ └── RTLL.cpp ├── EMPR.cpp ├── EQDIS.cpp ├── EQLZING.cpp ├── EXPRESSION_3.cpp ├── Exactly _N+1_Values.cpp ├── HIGHSCORE.cpp ├── July Cook-Off 2022 (COOK143D) │ ├── ACCURACY.cpp │ ├── ENSPACE.cpp │ ├── KMEX.cpp │ ├── PER_MED.cpp │ ├── TEA.cpp │ └── XORPERM.cpp ├── July Long One 2022 (JULY221D) │ ├── AUCTION.cpp │ ├── CHEFCAND.cpp │ ├── GAMEOFPILES1.cpp │ ├── KNIGHT2.cpp │ ├── PASSTHEEXAM.cpp │ └── SLOWSOLN.cpp ├── July Long Two 2022 (JULY222C) │ ├── BURGERS2.cpp │ ├── CONCATSORT.cpp │ ├── DIF_GCD.cpp │ ├── DIVAB.cpp │ ├── OFFICE.cpp │ └── SUMOFPROD1.cpp ├── July Lunchtime 2022 (LTIME110D) │ ├── EZSPEAK.cpp │ ├── INTRDSGN.cpp │ ├── LARGEFAM.cpp │ ├── LASTLEVELS.cpp │ ├── MAKEPALAGAIN.cpp │ └── TFPAPER.cpp ├── June Cook-Off 2022 (COOK142D) │ ├── ADVANCE.cpp │ ├── BREAKSTICK.cpp │ ├── FIRSTANDLAST.cpp │ ├── SIMPLE_XOR.cpp │ └── SONGS.cpp ├── June Long One 2022 (JUNE221D) │ ├── ALTERADD.cpp │ ├── CHAIRS_.cpp │ ├── DISTGCD.cpp │ ├── DIVBYI.cpp │ ├── EQUALSTRING.cpp │ └── SUBSCRIBE_.cpp ├── June Long Two 2022 (JUNE222D) │ ├── ACS.cpp │ ├── DNASTRAND.cpp │ ├── FIT.cpp │ ├── PAIREQ.cpp │ ├── REVSORT.cpp │ └── STRNG.cpp ├── KNGATK.cpp ├── LLMID.cpp ├── LUCNUM.cpp ├── Longest_AND_Subarray.cpp ├── MONSTER1.cpp ├── May Cook-Off 2022 (COOK141D) │ ├── CGYM.cpp │ └── CMASKS.cpp ├── May Long One 2022 (MAY221D) │ ├── F1RULE.cpp │ ├── FOOTCUP.cpp │ ├── QUEENATTACK.cpp │ └── SUGARCANE.cpp ├── May Lunchtime 2022 (LTIME108D) │ ├── APPLORNG.cpp │ ├── PRACLIST.cpp │ ├── TODOLIST.cpp │ └── WATERFLOW.cpp ├── OLYRANK.cpp ├── PRACTICEPERF.cpp ├── PRIZEPOOL.cpp ├── PROBDIFF.cpp ├── RTLL.cpp ├── SINGLEOP1.cpp ├── SINGLEOP2.cpp ├── SPCTRIPS.cpp ├── Save Water Save Life.py ├── TWOZERO.cpp ├── WATESTCASES.cpp ├── add.py ├── atm.py ├── chef_and_equality.cpp ├── chef_and_operators.py ├── chef_guard.py ├── ciel_&_receipt.py ├── cube_in_triangles.py ├── cupcakes.py ├── currency.py ├── dec_inc.py ├── diffsum.py ├── digit_sum.py ├── enormous_input_test.py ├── exoenses.py ├── factorial.py ├── gcd_lcm.py ├── helping_chef.py ├── holes_in_a_text.py ├── id&ship.py ├── lead_game.py ├── longestANDsubarray.cpp ├── lucky_four.py ├── mahasena.py ├── maxdistkt.cpp ├── min_max_lcm.cpp ├── palindrome.py ├── ppsum.py ├── primality.py ├── remainder.py ├── reverse.py ├── reverseint.js ├── second_largets.py ├── small_factorial.py ├── square_root.py ├── sum_1st&last_digit.py ├── tempCodeRunnerFile.py ├── turbo_sort.py └── valid_triangles.py ├── compositeprimeno.cpp ├── contribution guideline . md ├── coprime.cpp ├── cracking image ├── CSS Only Portrait.html ├── CSS Only Portrait_files │ ├── image.jpg │ ├── style.css │ └── texture.jpg ├── drew-hays-Kt8eGw8_S8Y-unsplash.jpg ├── dynamic-wang-3iixjTc--_k-unsplash.jpg ├── georgia-mashford-UzxZBo7nP9E-unsplash.jpg ├── index.html ├── ramin-khatibi-OG8L9s1bYKc-unsplash.jpg ├── style.css ├── texture.jpg └── vincent-burkhead-LhlxYMfnTF0-unsplash.jpg ├── cyclic component.cpp ├── doublycircular.cpp ├── doublylinkedlist.cpp ├── graph.cpp ├── hacktober.cpp ├── hello.cpp ├── initial.py ├── leetcode hard ├── Binary Tree Maximum Path Sum.cpp ├── EditDistance.cpp ├── FancySequence.cpp ├── KthSmallestProductof2SortedArrays.cpp ├── Largest Rectangle in Histogram.cpp ├── Longest Increasing Path in a Matrix.cpp ├── MaximumProfitinJobScheduling.cpp ├── Median_from_datastream.cpp ├── MergeKSortedLists.cpp ├── NQueens.cpp ├── SlidingWindowMaximum.cpp ├── minimum_window_substring.cpp ├── reverseNodes.java └── strongPasswordChecker.cpp ├── leetcodeproblems └── medium │ ├── clone_graph.cpp │ └── kth largest element in an array.cpp ├── list.py ├── maxProductSubset.cpp ├── maxSum.cpp ├── mergeSort.c ├── mergesort.cpp ├── minProductSubset.cpp ├── primeprint2.cpp ├── python ├── Dijkshtra_Shortest_Path_Algo.py ├── Merge Overlapping Intervals.py ├── analogClock.py ├── bynary_to_decimal.py ├── face_analyzer_deepface.py ├── fibonacci_sequence.py ├── min_path_sum.py ├── open_dir.py ├── random-resturant-generator.py ├── rock_paper_scissors_game.py ├── selenium_searching_script.py ├── transpose of a matrix.py └── youtube_video_downloader.py ├── singlycircularlinkedlist.cpp ├── singlylinkedlist.cpp ├── sumoftwonumber.cpp └── zFunction.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | .idea -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/Data-Structure-Algorithms.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "C_Cpp.errorSquiggles": "Disabled" 3 | } -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/Array waveform.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | // A utility method to swap two numbers. 6 | void swap(int *x, int *y) 7 | { 8 | int temp = *x; 9 | *x = *y; 10 | *y = temp; 11 | } 12 | 13 | // This function sorts arr[0..n-1] in wave form, i.e., 14 | // arr[0] >= arr[1] <= arr[2] >= arr[3] <= arr[4] >= arr[5].. 15 | void sortInWave(int arr[], int n) 16 | { 17 | // Sort the input array 18 | sort(arr, arr+n); 19 | 20 | // Swap adjacent elements 21 | for (int i=0; i n/2) { 15 | return nums[i]; 16 | } 17 | } 18 | 19 | return -1; 20 | } 21 | -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/Search2DMatrix1.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean searchMatrix(int[][] matrix, int target) { 3 | int row = matrix.length; 4 | int col = matrix[0].length; 5 | 6 | int start = 0; 7 | int end = row * col - 1; 8 | 9 | while(start <= end){ 10 | int mid = start + (end - start)/2; 11 | 12 | if(matrix[mid/col][mid%col] == target) 13 | return true; 14 | 15 | if(matrix[mid/col][mid%col] < target){ 16 | start = mid + 1; 17 | } 18 | else end = mid - 1; 19 | 20 | } 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/Search2DMatrix2.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public boolean searchMatrix(int[][] matrix, int target) { 3 | int rows = matrix.length; 4 | int col = matrix[0].length; 5 | 6 | int rowIdx = 0; 7 | int colIdx = col - 1; 8 | 9 | while(rowIdx < rows && colIdx >= 0){ 10 | int val = matrix[rowIdx][colIdx]; 11 | 12 | if(val == target){ 13 | return true; 14 | } 15 | if(val < target){ 16 | rowIdx++; 17 | } 18 | else colIdx--; 19 | } 20 | 21 | return false; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/Smallest positive missing.cpp: -------------------------------------------------------------------------------- 1 | int getMEX(vector < int > & a) { 2 | bool found = false; 3 | for (int i = 1;; i++) { 4 | found = false; 5 | for (auto x: a) { 6 | if (x == i) { 7 | found = true; 8 | break; 9 | } 10 | } 11 | if (!found) { 12 | return i; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/Trappinf rainwater.cpp: -------------------------------------------------------------------------------- 1 | int volumeOfTrappedRainWater(vector &heights) { 2 | int n = heights.size(); 3 | int totalRainWater = 0; 4 | for (int i = 0; i < n; i++){ 5 | int maxLeft = 0, maxRight = 0; 6 | for (int j = 0; j <= i; j++){ 7 | maxLeft = max (maxLeft, heights[j]); 8 | } 9 | for (int j = i; j < n; j++) { 10 | maxRight = max (maxRight, heights[j]); 11 | } 12 | totalRainWater += min (maxRight, maxLeft) - heights[i]; 13 | } 14 | return totalRainWater; 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/WavePrint.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | public static int[] wavePrint(int arr[][], int nRows, int mCols) { 3 | // Write your code here. 4 | int[] ans = new int[nRows * mCols]; // array to store the values of wave and return 5 | 6 | int idx = 0; // index for traversing the ans indexes 7 | 8 | // Here i represents columns & j represents Rows 9 | for(int i = 0; i < mCols; i++){ 10 | 11 | if(i % 2 != 0){ // bottom to top 12 | 13 | for(int j = nRows - 1; j >= 0; j--){ 14 | ans[idx++] = arr[j][i]; 15 | } 16 | } 17 | else { // top to bottom 18 | for(int j = 0; j < nRows; j++){ 19 | ans[idx++] = arr[j][i]; 20 | } 21 | } 22 | } 23 | 24 | return ans; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/search2DMatrix2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | class Solution { 5 | public: 6 | bool searchMatrix(vector >& matrix, int target) { 7 | 8 | int row = matrix.size(); 9 | int col = matrix[0].size(); 10 | 11 | int rowIndex = 0; 12 | int colIndex = col-1; 13 | 14 | while(rowIndex < row && colIndex>=0 ) { 15 | int element = matrix[rowIndex][colIndex]; 16 | 17 | if(element == target) { 18 | return 1; 19 | } 20 | 21 | if(element < target){ 22 | rowIndex++; 23 | } 24 | else 25 | { 26 | colIndex--; 27 | } 28 | } 29 | return 0; 30 | } 31 | }; -------------------------------------------------------------------------------- /Algorithms CPP/2D arrays/wavePrint.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | vector wavePrint(vector > arr, int nRows, int mCols) 5 | { 6 | vector ans; 7 | 8 | for(int col=0; col Bottom to top 12 | 13 | for(int row = nRows-1; row>=0; row--) { 14 | //cout << arr[row][col] <<" "; 15 | ans.push_back(arr[row][col]); 16 | } 17 | } 18 | else 19 | { 20 | // 0 or even iondex -> top to bottom 21 | for(int row = 0; row 2 | using namespace std; 3 | int main(){ 4 | int n,k; 5 | cout<<"Enter size of array=\t"; 6 | cin>>n; 7 | cout<<"Enter Number of indeces u want to rotate the array to left=\t"; 8 | cin>>k; 9 | int a[n]; 10 | cout<<"Enter elements of array=\t"; 11 | for(int i=0;i>a[i]; 13 | } 14 | int temp=0; 15 | for(int i=0;i 2 | using namespace std; 3 | int main(){ 4 | int n,k; 5 | cout<<"Enter size of array=\t"; 6 | cin>>n; 7 | cout<<"Enter Number of indices u want to rotate the array to right=\t"; 8 | cin>>k; 9 | int a[n]; 10 | cout<<"Enter elements of array=\t"; 11 | for(int i=0;i>a[i]; 13 | int temp=0; 14 | for(int i=0;i=0;j--){ 17 | if(j==0){ 18 | a[j]=temp; 19 | } 20 | else{ 21 | a[j]=a[j-1];} 22 | 23 | } 24 | 25 | } 26 | cout<<"Your rotated array is=\t"; 27 | for(int i=0;i 2 | using namespace std; 3 | 4 | void bubbleSort(int arr[], int n) 5 | { 6 | 7 | if (n == 1) 8 | return; 9 | 10 | int count = 0; 11 | 12 | for (int i=0; i arr[i+1]){ 14 | swap(arr[i], arr[i+1]); 15 | count++; 16 | } 17 | 18 | if (count==0) 19 | return; 20 | 21 | bubbleSort(arr, n-1); 22 | } 23 | 24 | void printArray(int arr[], int n) 25 | { 26 | for (int i=0; i < n; i++) 27 | printf("%d ", arr[i]); 28 | printf("\n"); 29 | } 30 | 31 | int main() 32 | { 33 | int arr[] = {64, 34, 25, 12, 22, 11, 90}; 34 | int n = sizeof(arr)/sizeof(arr[0]); 35 | bubbleSort(arr, n); 36 | printf("Sorted array : \n"); 37 | printArray(arr, n); 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Algorithms CPP/BucketSort.cpp: -------------------------------------------------------------------------------- 1 | // BUCKET SORT 2 | 3 | // Time Complexity : O(n) 4 | // Space Compplexity : O(m+n) = O(n) 5 | 6 | #include 7 | using namespace std; 8 | 9 | void bucketSort(float arr[], int n) 10 | { 11 | vector b[n]; 12 | for (int i = 0; i < n; i++){ 13 | int bi = n * arr[i]; 14 | b[bi].push_back(arr[i]); 15 | } 16 | 17 | for (int i = 0; i < n; i++){ 18 | sort(b[i].begin(), b[i].end()); 19 | } 20 | int index = 0; 21 | for (int i = 0; i < n; i++){ 22 | for (int j = 0; j < b[i].size(); j++){ 23 | arr[index++] = b[i][j]; 24 | } 25 | } 26 | } 27 | 28 | int main() 29 | { 30 | float arr[] = { 0.897, 0.565, 0.656, 0.1234, 0.665, 0.3434 }; 31 | int n = sizeof(arr) / sizeof(arr[0]); 32 | bucketSort(arr, n); 33 | 34 | cout<<"Sorted array is : \n"; 35 | for(int i = 0; i < n; i++){ 36 | cout << arr[i] << " "; 37 | } 38 | return 0; 39 | } -------------------------------------------------------------------------------- /Algorithms CPP/C. Delete Two Elements.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | question link--https://codeforces.com/contest/1598/problem/C 4 | 5 | */ 6 | 7 | 8 | #include 9 | using namespace std; 10 | int main(){ 11 | int t;scanf("%d",&t); 12 | while(t--){ 13 | int n;scanf("%d",&n); 14 | // std::vector v; 15 | vector v(n); 16 | map count; 17 | for(auto &x:v){ 18 | scanf("%d",&x); 19 | count[x]++; 20 | } 21 | long long int sum=accumulate(v.begin(),v.end(),0LL); 22 | if((2*sum)%n==0){ 23 | long long int need = 2*sum/n; 24 | long long ans=0LL; 25 | for(int i=0;ibrr[i]) 27 | 28 | 29 | 30 | 31 | return false; 32 | 33 | 34 | 35 | 36 | } 37 | 38 | 39 | 40 | 41 | return true; 42 | 43 | 44 | 45 | 46 | } 47 | 48 | 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /Algorithms CPP/Create Fitting The Array.cpp: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | 3 | public static boolean isFit (int arr[], int brr[], int n) { 4 | 5 | Arrays.sort(arr); 6 | 7 | Arrays.sort(brr); 8 | 9 | for(int i=0;ibrr[i]) 12 | 13 | return false; 14 | 15 | } 16 | 17 | return true; 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Algorithms CPP/DFS: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | 5 | class Graph 6 | { 7 | public: 8 | map visited; 9 | map> adj; 10 | 11 | void addEdge(int v, int w); 12 | 13 | void DFS(int v); 14 | }; 15 | 16 | void Graph::addEdge(int v, int w) 17 | { 18 | adj[v].push_back(w); 19 | } 20 | 21 | void Graph::DFS(int v) 22 | { 23 | visited[v] = true; 24 | cout << v << " "; 25 | 26 | list::iterator i; 27 | for (i = adj[v].begin(); i != adj[v].end(); ++i) 28 | if (!visited[*i]) 29 | DFS(*i); 30 | } 31 | 32 | int main() 33 | { 34 | Graph g; 35 | g.addEdge(0, 1); 36 | g.addEdge(0, 2); 37 | g.addEdge(1, 2); 38 | g.addEdge(2, 0); 39 | g.addEdge(2, 3); 40 | g.addEdge(3, 3); 41 | 42 | cout << "Following is Depth First Traversal" 43 | " (starting from vertex 2) \n"; 44 | g.DFS(2); 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Algorithms CPP/Edit Distance.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | int diff(int, int); 5 | using namespace std; 6 | string X, Y; 7 | int main() 8 | { 9 | ios::sync_with_stdio(0); 10 | cin >> X; 11 | cin >> Y; 12 | int m = X.length(); 13 | int n = Y.length(); 14 | int **E = new int*[m + 1]; 15 | for (int i = 0; i < m + 1; i++) 16 | { 17 | E[i] = new int[n + 1]; 18 | } 19 | for (int i = 0; i < m + 1; i++) 20 | { 21 | E[i][0] = i; 22 | } 23 | for (int j = 0; j < n + 1; j++) 24 | { 25 | E[0][j] = j; 26 | } 27 | for (int i = 1; i < m + 1; i++) 28 | { 29 | for (int j = 1; j < n + 1; j++) 30 | { 31 | E[i][j] = min({ 1 + E[i - 1][j], 1 + E[i][j - 1], diff(i, j) + E[i - 1][j - 1] }); 32 | } 33 | } 34 | cout << E[m][n]; 35 | } 36 | int diff(int i, int j) 37 | { 38 | if (X[i-1] == Y[j-1]) 39 | return 0; 40 | else 41 | return 1; 42 | } 43 | -------------------------------------------------------------------------------- /Algorithms CPP/Graph/Search in maze.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ref: backtracking/1_rat_in_maze 3 | */ -------------------------------------------------------------------------------- /Algorithms CPP/Greedy.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int n1=0,n2=1,n3,i,number; 5 | printf("Enter the number of elements:"); 6 | scanf("%d",&number); 7 | printf("\n%d %d",n1,n2);//printing 0 and 1 8 | for(i=2;i> groupAnagrams(vector& strs) { 4 | map>mp; 5 | int n = strs.size(); 6 | for(int i=0;i>ans; 12 | map> :: iterator itr; 13 | // cout< arr = itr->second; 16 | // cout<temp; 18 | for(int i=0;i 3 | using namespace std; 4 | 5 | void insertionSortRecursive(int arr[], int n) 6 | { 7 | 8 | if (n <= 1) 9 | return; 10 | 11 | insertionSortRecursive( arr, n-1 ); 12 | 13 | int last = arr[n-1]; 14 | int j = n-2; 15 | 16 | while (j >= 0 && arr[j] > last) 17 | { 18 | arr[j+1] = arr[j]; 19 | j--; 20 | } 21 | arr[j+1] = last; 22 | } 23 | 24 | void printArray(int arr[], int n) 25 | { 26 | for (int i=0; i < n; i++) 27 | cout << arr[i] <<" "; 28 | } 29 | 30 | int main() 31 | { 32 | int arr[] = {12, 11, 13, 5, 6}; 33 | int n = sizeof(arr)/sizeof(arr[0]); 34 | 35 | insertionSortRecursive(arr, n); 36 | printArray(arr, n); 37 | 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Algorithms CPP/Intersection_of_2_arrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int i,j,m,n; 5 | cout <<"Enter size of array 1:"; 6 | cin >> m; 7 | cout <<"Enter size of array 2:"; 8 | cin >> n; 9 | int a[m]; 10 | int b[n]; 11 | cout <<"Enter elements of array 1:"; 12 | for(i=0;i> a[i]; 14 | for(i=0;i> b[i]; 16 | i=0;j=0; 17 | while((ib[j]) 22 | j++; 23 | else 24 | { 25 | cout << a[i++]<<" "; 26 | j++; 27 | } 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Algorithms CPP/JumpSearch.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int jumpSearch( int arr[], int L, int key) 6 | { 7 | int step = sqrt(L); 8 | int left = 0; 9 | int right = step; 10 | 11 | while(arr[right]<= key && right <= L) 12 | { 13 | left = right; 14 | right = right + step; 15 | 16 | if( right > L-1) 17 | { 18 | right = L-1; 19 | } 20 | } 21 | 22 | 23 | for( int i = left; i <= right; i++) 24 | { 25 | if(arr[i] == key) 26 | { 27 | return i; 28 | } 29 | } 30 | return -1; 31 | } 32 | 33 | int main() 34 | { 35 | int arr[] = {5,10,15,20,25,30,35,40,45,50,55,60,65,70}; 36 | int L = sizeof(arr)/ sizeof(arr[0]); 37 | 38 | cout<<"Enter the number to be searched"<> key; 42 | 43 | int result = jumpSearch( arr , L, key); 44 | 45 | cout<< result; 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Algorithms CPP/Kadane's Algorithm: -------------------------------------------------------------------------------- 1 | class Solution{ 2 | public: 3 | // arr: input array 4 | // n: size of array 5 | //Function to find the sum of contiguous subarray with maximum sum. 6 | long long maxSubarraySum(int arr[], int n){ 7 | int res=arr[0]; 8 | int maxEnding = arr[0]; 9 | for(int i=1;i 2 | using namespace std; 3 | int kadane(int arr[], int n) 4 | { 5 | 6 | int max_so_far = 0; 7 | int max_ending_here = 0; 8 | 9 | for (int i = 0; i < n; i++) 10 | { 11 | max_ending_here = max_ending_here + arr[i]; 12 | 13 | max_ending_here = max(max_ending_here, 0); 14 | 15 | max_so_far = max(max_so_far, max_ending_here); 16 | } 17 | 18 | return max_so_far; 19 | } 20 | 21 | int main() 22 | { 23 | int arr[] = { -2, 1, -3, 4, -1, 2, 1, -5, 4 }; 24 | int n = sizeof(arr)/sizeof(arr[0]); 25 | 26 | cout << "The maximum sum of a contiguous subarray is " << 27 | kadane(arr, n); 28 | 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Algorithms CPP/LCS.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int max(int a, int b); 5 | int lcs( char *X, char *Y, int m, int n ) 6 | { 7 | if (m == 0 || n == 0) 8 | return 0; 9 | if (X[m-1] == Y[n-1]) 10 | return 1 + lcs(X, Y, m-1, n-1); 11 | else 12 | return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n)); 13 | } 14 | 15 | int max(int a, int b) 16 | { 17 | return (a > b)? a : b; 18 | } 19 | 20 | int main() 21 | { 22 | char X[] = "AGGTAB"; 23 | char Y[] = "GXTXAYB"; 24 | 25 | int m = strlen(X); 26 | int n = strlen(Y); 27 | 28 | cout<<"Length of Longest Common Subsequence is "<< lcs( X, Y, m, n ) ; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Algorithms CPP/MCM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int MatrixChainOrder(int p[], int i, int j) 5 | { 6 | if (i == j) 7 | return 0; 8 | int k; 9 | int min = INT_MAX; 10 | int count; 11 | for (k = i; k < j; k++) 12 | { 13 | count = MatrixChainOrder(p, i, k) 14 | + MatrixChainOrder(p, k + 1, j) 15 | + p[i - 1] * p[k] * p[j]; 16 | 17 | if (count < min) 18 | min = count; 19 | } 20 | 21 | return min; 22 | } 23 | 24 | int main() 25 | { 26 | int arr[] = { 1, 2, 3, 4, 3 }; 27 | int n = sizeof(arr) / sizeof(arr[0]); 28 | 29 | cout << "Minimum number of multiplications is " 30 | << MatrixChainOrder(arr, 1, n - 1); 31 | } 32 | -------------------------------------------------------------------------------- /Algorithms CPP/NthPrime.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int nthprime(int num){ 5 | int t=0; 6 | for (int i=1;i>=1;i++){ 7 | int a=0; 8 | for (int j=2;j<=i/2;j++){ 9 | if (i%j==0){ 10 | a=1; 11 | break; 12 | } 13 | } 14 | if (a==0 && i!=1){ 15 | t++; 16 | if (t==num){ 17 | return i; 18 | } 19 | } 20 | } 21 | } 22 | 23 | int main() 24 | { 25 | int n; 26 | cin>>n; 27 | cout< rev(queue q) 2 | { 3 | stack s; 4 | 5 | while(!q.empty()) { 6 | int element = q.front(); 7 | q.pop(); 8 | s.push(element); 9 | } 10 | 11 | while(!s.empty()) { 12 | int element = s.top(); 13 | s.pop(); 14 | q.push(element); 15 | } 16 | return q; 17 | } -------------------------------------------------------------------------------- /Algorithms CPP/RainWaterTrapping.cpp: -------------------------------------------------------------------------------- 1 | int trap(vector& height) { 2 | int n = height.size(); 3 | vector leftMax(n), rightMax(n); 4 | for (int i = 1; i < n; ++i) 5 | leftMax[i] = max(height[i-1], leftMax[i-1]); 6 | for (int i = n-2; i >= 0; --i) 7 | rightMax[i] = max(height[i+1], rightMax[i+1]); 8 | 9 | int ans = 0; 10 | for (int i = 0; i < n; ++i) { 11 | int waterLevel = min(leftMax[i], rightMax[i]); 12 | if (waterLevel >= height[i]) ans += waterLevel - height[i]; 13 | } 14 | return ans; 15 | } 16 | -------------------------------------------------------------------------------- /Algorithms CPP/Recover Binary Search Tree.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | TreeNode* firstMistake, *secondMistake, *pre; 4 | void recoverTree(TreeNode* root) { 5 | pre = new TreeNode(INT_MIN); 6 | inorder(root); 7 | swap(firstMistake->val, secondMistake->val); 8 | } 9 | 10 | void inorder(TreeNode* root) { 11 | if(root == nullptr) 12 | return; 13 | 14 | inorder(root->left); 15 | 16 | if(firstMistake == nullptr && root->val < pre->val) 17 | firstMistake = pre; 18 | if(firstMistake != nullptr && root->val < pre->val) 19 | secondMistake = root; 20 | pre = root; 21 | 22 | inorder(root->right); 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /Algorithms CPP/RodCutting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int max(int a, int b) { return (a > b)? a : b;} 7 | int cutRod(int price[], int n) 8 | { 9 | int val[n+1]; 10 | val[0] = 0; 11 | int i, j; 12 | 13 | for (i = 1; i<=n; i++) 14 | { 15 | int max_val = INT_MIN; 16 | for (j = 0; j < i; j++) 17 | max_val = max(max_val, price[j] + val[i-j-1]); 18 | val[i] = max_val; 19 | } 20 | 21 | return val[n]; 22 | } 23 | 24 | int main() 25 | { 26 | int arr[] = {1, 5, 8, 9, 10, 17, 17, 20}; 27 | int size = sizeof(arr)/sizeof(arr[0]); 28 | cout <<"Maximum Obtainable Value is "< 2 | using namespace std; 3 | 4 | int minIndex(int a[], int i, int j) 5 | { 6 | if (i == j) 7 | return i; 8 | 9 | int k = minIndex(a, i + 1, j); 10 | 11 | return (a[i] < a[k])? i : k; 12 | } 13 | 14 | void recurSelectionSort(int a[], int n, int index = 0) 15 | { 16 | 17 | if (index == n) 18 | return; 19 | 20 | int k = minIndex(a, index, n-1); 21 | 22 | if (k != index) 23 | swap(a[k], a[index]); 24 | 25 | recurSelectionSort(a, n, index + 1); 26 | } 27 | 28 | int main() 29 | { 30 | int arr[] = {3, 1, 5, 2, 7, 0}; 31 | int n = sizeof(arr)/sizeof(arr[0]); 32 | 33 | recurSelectionSort(arr, n); 34 | 35 | for (int i = 0; i 2 | #include 3 | using namespace std; 4 | 5 | void reverse_with_array(char C[] ,int n) 6 | { 7 | //putting all values in stack 8 | stack S; 9 | for(int i=0; i&inputStack, int count, int size) { 3 | //base case 4 | if(count == size/2) { 5 | inputStack.pop(); 6 | return ; 7 | } 8 | 9 | int num = inputStack.top(); 10 | inputStack.pop(); 11 | 12 | //RECURSIVE CALL 13 | solve(inputStack, count+1, size); 14 | 15 | inputStack.push(num); 16 | 17 | } 18 | 19 | void deleteMiddle(stack&inputStack, int N){ 20 | 21 | int count = 0; 22 | solve(inputStack, count, N); 23 | 24 | } -------------------------------------------------------------------------------- /Algorithms CPP/Stack/deleteMiddleElementStack.cpp: -------------------------------------------------------------------------------- 1 | // removing middle elment from stack 2 | 3 | 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | void solve(stack&inputStack, int count, int size) { // size 9 | //base case 10 | 11 | if(count == size/2) { 12 | inputStack.pop(); 13 | return ; 14 | } 15 | 16 | int num = inputStack.top(); 17 | inputStack.pop(); 18 | 19 | // RECURSIVE CALL 20 | solve(inputStack, count+1, size); 21 | inputStack.push(num); 22 | 23 | } 24 | 25 | void deleteMiddle(stack&inputStack, int N) { 26 | 27 | int count = 0; 28 | solve(inputStack, count, N); 29 | } 30 | -------------------------------------------------------------------------------- /Algorithms CPP/Stack/insertAtBottom.cpp: -------------------------------------------------------------------------------- 1 | void solve(stack& s, int x) { 2 | //base case 3 | if(s.empty()) { 4 | s.push(x); 5 | return ; 6 | } 7 | 8 | int num = s.top(); 9 | s.pop(); 10 | 11 | //recursive call 12 | solve(s, x); 13 | 14 | s.push(num); 15 | } 16 | 17 | 18 | stack pushAtBottom(stack& myStack, int x) 19 | { 20 | solve(myStack, x); 21 | return myStack; 22 | } 23 | -------------------------------------------------------------------------------- /Algorithms CPP/Stack/reverseString.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | 6 | 7 | int main () { 8 | string str = "babbar"; 9 | 10 | stack s; 11 | 12 | for (int i = 0; i 5 | #include 6 | using namespace std; 7 | 8 | void sortedInsert(stack &stack, int num) { 9 | // base case 10 | if(stack.empty() || (!stack.empty() && stack.top() < num)) { 11 | stack.push(num); 12 | return; 13 | } 14 | 15 | int n = stack.top(); 16 | stack.pop(); 17 | 18 | // recursive call 19 | sortedInsert(stack , num); 20 | } 21 | 22 | 23 | void sortStack(stack &stack) 24 | { 25 | // base class 26 | if(stack.empty()) { 27 | return ; 28 | } 29 | 30 | int num = stack.top(); 31 | stack.pop(); 32 | 33 | 34 | // recursive call 35 | sortStack(stack); 36 | 37 | sortedInsert(stack, num); 38 | } -------------------------------------------------------------------------------- /Algorithms CPP/Strings/Finding_Duplicates_In_A_String.c: -------------------------------------------------------------------------------- 1 | //Finding Duplicates in a string 2 | 3 | #include 4 | 5 | // ASCII Code for 'a' == 97 6 | // Using "Hashing",not really hash tables 7 | // This function will only work for lower case alphabets 8 | // Time Complexity: O(n) 9 | void duplicates(char * s) { 10 | 11 | int ht[26] = {0}; 12 | 13 | for (int i = 0; s[i] != '\0'; i++) 14 | ht[s[i] - 97]++; 15 | 16 | for (int i = 0; i < 26; i++) { 17 | if (ht[i] > 1) 18 | printf("There are %d elements of letter %c\n", ht[i], i+97); 19 | } 20 | } 21 | 22 | int main() { 23 | char s[] = "findiiing"; 24 | duplicates(s); 25 | 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Algorithms CPP/Tower Of Hanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | //tower of HANOI function implementation 5 | void TOH(int n,char A, char B,char C) 6 | { 7 | if(n==1) 8 | { 9 | cout<<"Move Disk "<>n; 25 | //calling the TOH 26 | TOH(n,'A','B','C'); 27 | 28 | return 0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Algorithms CPP/TowerOfHanoi.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void towerOfHanoi(int n, char from_rod, char to_rod, 5 | char aux_rod) 6 | { 7 | if (n == 0) { 8 | return; 9 | } 10 | towerOfHanoi(n - 1, from_rod, aux_rod, to_rod); 11 | cout << "Move disk " << n << " from rod " << from_rod 12 | << " to rod " << to_rod << endl; 13 | towerOfHanoi(n - 1, aux_rod, to_rod, from_rod); 14 | } 15 | 16 | 17 | int main() 18 | { 19 | int N = 3; 20 | 21 | 22 | towerOfHanoi(N, 'A', 'C', 'B'); 23 | return 0; 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /Algorithms CPP/Union_of_2_arrays.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int m,n,i=0,j=0; 5 | cout << "Enter size of both arrays:"; 6 | cin >> m >> n; 7 | int a[m]; 8 | int b[n]; 9 | cout << "Enter elements of array 1:"; 10 | for(i=0;i>a[i]; 12 | cout << "Enter elements of array 2:"; 13 | for(i=0;i> b[i]; 15 | i=0;j=0; 16 | while((ib[j]) 21 | cout << b[j++] <<" "; 22 | else 23 | { 24 | cout << a[i++]; 25 | j++; 26 | } 27 | } 28 | while(i 2 | using namespace std; 3 | int main() 4 | { 5 | int n,r,sum=0,temp; 6 | cout<<"Enter the Number= "; 7 | cin>>n; 8 | temp=n; 9 | while(n>0) 10 | { 11 | r=n%10; 12 | sum=sum+(r*r*r); 13 | n=n/10; 14 | } 15 | if(temp==sum) 16 | cout<<"Armstrong Number."< 2 | using namespace std; 3 | void printArray(int input[],int n){ 4 | for(int i=0;i0){ 14 | for(int i=0;iinput[i+1]){ 16 | swap(input[i],input[i+1]); 17 | } 18 | 19 | 20 | }j--; 21 | 22 | } 23 | } 24 | int main(){ 25 | int n; 26 | cin>>n; 27 | int input[100]; 28 | for(int i=0;i>input[i]; 30 | } 31 | bubbleSort(input,n); 32 | printArray(input,n); 33 | return 0; 34 | } 35 | -------------------------------------------------------------------------------- /Algorithms CPP/bubble_sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void bubble(int n, int *arr){ 5 | 6 | for(int i=0;iarr[j])// 11 | { 12 | int t=arr[i]; 13 | arr[i]=arr[j]; 14 | arr[j]=t; 15 | } 16 | 17 | } 18 | 19 | } 20 | for(int i=0;i 2 | using namespace std; 3 | void swapp(int *a,int *b){ 4 | int temp= *b; 5 | *b=*a; 6 | *a=temp; 7 | } 8 | void Bubble_sort(int arr[],int n){ 9 | int temp; 10 | for(int i=0;i 2 | using namespace std; 3 | int main() 4 | { 5 | int arr[10], tot, i, elem, j, found=0; 6 | cout<<"Enter the Size: "; 7 | cin>>tot; 8 | cout<<"Enter "<>arr[i]; 11 | cout<<"\nEnter Element to Delete: "; 12 | cin>>elem; 13 | for(i=0; i 3 | using namespace std; 4 | 5 | int gcd(int a, int b) 6 | { 7 | return b == 0 ? a : gcd(b, a % b); 8 | } 9 | 10 | int32_t main() 11 | { 12 | int a = 98, b = 56; 13 | cout << "GCD of " << a << " and " << b << " is " << gcd(a, b); 14 | return 0; 15 | } 16 | 17 | /* 18 | 19 | 20 | #include 21 | using namespace std; 22 | 23 | int func() 24 | { 25 | 26 | } 27 | 28 | int32_t main() 29 | { 30 | 31 | return 0; 32 | } 33 | 34 | 35 | 36 | */ -------------------------------------------------------------------------------- /Algorithms CPP/insertion-sort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void printArray(int input[],int n){ 4 | for(int i=0;i=0;j--){ 13 | if(input[j]>current){ 14 | input[j+1]=input[j]; 15 | } 16 | else{ 17 | break; 18 | } 19 | } 20 | input[j+1]=current; 21 | } 22 | } 23 | int main(){ 24 | int n; 25 | cin>>n; 26 | int input[100]; 27 | for(int i=0;i>input[i]; 29 | } 30 | insertionSort(input,n); 31 | printArray(input,n); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /Algorithms CPP/insertion_sort.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | using namespace std; 4 | void swapp(int *a,int *b){ 5 | int temp= *b; 6 | *b=*a; 7 | *a=temp; 8 | } 9 | 10 | 11 | void insertion_sort(int arr[],int n){ 12 | 13 | for(int i=1;i=0 &&arr[j]>temp;j--){ 17 | 18 | arr[j+1]=arr[j]; 19 | } 20 | arr[j+1]=temp; 21 | } 22 | 23 | 24 | } 25 | void print(int arr[],int n){ 26 | for(int i=0;i 3 | #include 4 | using namespace std; 5 | 6 | int maxSubArraySum(int a[], int size) 7 | { 8 | int max_so_far = INT_MIN, max_ending_here = 0; 9 | 10 | for (int i = 0; i < size; i++) 11 | { 12 | max_ending_here = max_ending_here + a[i]; 13 | if (max_so_far < max_ending_here) 14 | max_so_far = max_ending_here; 15 | 16 | if (max_ending_here < 0) 17 | max_ending_here = 0; 18 | } 19 | return max_so_far; 20 | } 21 | 22 | /*Driver program to test maxSubArraySum*/ 23 | int main() 24 | { 25 | int a[] = {-2, -3, 4, -1, -2, 1, 5, -3}; 26 | int n = sizeof(a)/sizeof(a[0]); 27 | int max_sum = maxSubArraySum(a, n); 28 | cout << "Maximum contiguous sum is " << max_sum; 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /Algorithms CPP/max_difference.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | int main() 4 | { 5 | int days,max=0,*A; 6 | cout<<"Enter no. of days\n"; 7 | cin>>days; 8 | A=(int*)malloc(days*sizeof(int)); 9 | for(int i=0;i>A[i]; 12 | } 13 | for(int i=0;imax) 18 | { 19 | max=A[j]-A[i]; 20 | } 21 | } 22 | } 23 | cout< 2 | using namespace std; 3 | 4 | 5 | int main() { 6 | int n; 7 | cout<<"enter a no: "; 8 | cin>>n; 9 | int n1=(n+1)/2; 10 | int i=1; 11 | while(i<=n1){ 12 | int k=1; 13 | while(k<=n1-i){ 14 | cout<<" "; 15 | k++; 16 | } 17 | int j=1; 18 | while(j<=2*i-1){ 19 | cout<<"*"; 20 | j++; 21 | } 22 | cout<=1){ 29 | int k=1; 30 | while(k<=n1-i){ 31 | cout<<" "; 32 | k++; 33 | } 34 | int j=1; 35 | while(j<=2*i-1){ 36 | cout<<"*"; 37 | j++; 38 | } 39 | cout< 2 | using namespace std; 3 | bool prime(int n){ 4 | for(int i=2;i 2 | using namespace std; 3 | vector result; // act as a container stores all the combination created by the string_combination function 4 | void string_combination(string str, string level_str,int level) 5 | { 6 | if(level==str.length()) 7 | { 8 | result.push_back(level_str); 9 | return; 10 | } 11 | level_str.push_back(str[level]); 12 | string_combination(str,level_str,level+1); 13 | level_str.pop_back(); 14 | string_combination(str,level_str,level+1); 15 | } 16 | int main() 17 | { 18 | string str,level_str; 19 | cout<<"please enter the string:-"; 20 | cin>>str; 21 | string_combination(str,level_str,0); 22 | cout<<"printing all combination of a string"< 2 | using namespace std; 3 | int a[51]; 4 | int front =-1; 5 | int rear =-1; 6 | void enqueue(int x){ 7 | if(rear==51){ 8 | cout<<"underflow"; 9 | return; 10 | } 11 | if(front==-1) front++; 12 | a[++rear]=x; 13 | } 14 | void dequeue(){ 15 | if(front==-1 && rear==-1){ 16 | cout<<"underflow"; 17 | return; 18 | } 19 | if(front==rear){ 20 | front=-1; 21 | rear=-1; 22 | return; 23 | } 24 | front++; 25 | } 26 | bool isEmpty(){ 27 | if(rear==-1 && front==-1) return true; 28 | return false; 29 | } 30 | void print(){ 31 | for(int i=front;i<=rear;i++){ 32 | cout<>n; 40 | while(n--){ 41 | cout<<"Enter x: "; 42 | cin>>x; 43 | enqueue(x); 44 | } 45 | print(); 46 | dequeue(); 47 | print(); 48 | } 49 | -------------------------------------------------------------------------------- /Algorithms CPP/reverse linkedlist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct node{ 4 | int data; 5 | node* next; 6 | }; 7 | struct node* head; 8 | void print(){ 9 | node* temp=head; 10 | while(temp->next!=NULL){ 11 | cout<data<<"\t"; 12 | temp=temp->next; 13 | } 14 | cout<<"\n"; 15 | } 16 | int main(){ 17 | node* prev=NULL; 18 | node* curr=head; 19 | node*next; 20 | while(curr->next!=NULL){ 21 | next=curr->next; 22 | curr->next=prev; 23 | prev=curr; 24 | curr=next; 25 | next=next->next; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Algorithms CPP/reverse-array.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | void reverse(int input[], int n){ 4 | int temp=input[0]; 5 | input[0]=input[n-1]; 6 | input[n-1]=temp; 7 | } 8 | void printArray(int input[],int n){ 9 | for(int i=1;i>n; 16 | int b[10] = {1,5,4}; 17 | reverse(b,3); 18 | printArray(b,3); 19 | } 20 | -------------------------------------------------------------------------------- /Algorithms CPP/reverse.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int n, reversedNumber = 0, remainder; 6 | 7 | cout << "Enter an integer: "; 8 | cin >> n; 9 | 10 | while(n != 0) { 11 | remainder = n%10; 12 | reversedNumber = reversedNumber*10 + remainder; 13 | n /= 10; 14 | } 15 | 16 | cout << "Reversed Number = " << reversedNumber; 17 | 18 | return 0; 19 | } -------------------------------------------------------------------------------- /Algorithms CPP/slidingWindow.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int maxSum(int arr[], int n, int k) 5 | { 6 | int max_sum = INT_MIN; 7 | 8 | for (int i = 0; i < n - k + 1; i++) { 9 | int current_sum = 0; 10 | for (int j = 0; j < k; j++) 11 | current_sum = current_sum + arr[i + j]; 12 | 13 | max_sum = max(current_sum, max_sum); 14 | } 15 | 16 | return max_sum; 17 | } 18 | 19 | int main() 20 | { 21 | int arr[] = { 1, 4, 2, 10, 2, 3, 1, 0, 20 }; 22 | int k = 4; 23 | int n = sizeof(arr) / sizeof(arr[0]); 24 | cout << maxSum(arr, n, k); 25 | return 0; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /Algorithms CPP/sort_bubble.dart: -------------------------------------------------------------------------------- 1 | void main() { 2 | List array = [5, 1, 4, 2, 8]; 3 | List sortedarray = bubbleSort(array); 4 | print(sortedarray); 5 | } 6 | 7 | bubbleSort(List array) { 8 | int lengthOfArray = array.length; 9 | for (int i = 0; i < lengthOfArray - 1; i++) { 10 | for (int j = 0; j < lengthOfArray - i - 1; j++) { 11 | 12 | if (array[j] > array[j + 1]) { 13 | int temp = array[j]; 14 | array[j] = array[j + 1]; 15 | array[j + 1] = temp; 16 | 17 | } 18 | } 19 | } 20 | return (array); 21 | } -------------------------------------------------------------------------------- /Algorithms CPP/stack using linkedlist.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | struct node{ 4 | int data; 5 | node* next; 6 | }; 7 | node* top=NULL; 8 | void push(int x){ 9 | node* temp=new node(); 10 | temp->data=x; 11 | temp->next=NULL; 12 | if(top==NULL){ 13 | top=temp; 14 | return; 15 | } 16 | temp->next=top; 17 | top=temp; 18 | } 19 | void pop(){ 20 | node* temp=top; 21 | if(top==NULL){ 22 | cout<<"underflow"; 23 | return; 24 | } 25 | top=temp->next; 26 | free(temp); 27 | } 28 | void print(){ 29 | node* temp=top; 30 | while(temp!=NULL){ 31 | cout<data<<" "; 32 | temp=temp->next; 33 | } 34 | } 35 | int main(){ 36 | int n,x; 37 | cout<<"Enter n: "; 38 | cin>>n; 39 | for(int i=0;i>x; 42 | push(x); 43 | } 44 | pop(); 45 | print(); 46 | } 47 | -------------------------------------------------------------------------------- /Algorithms CPP/sum-even-odd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | // Write your code here 6 | int num; 7 | cin>>num; 8 | int sum_e=0, sum_o=0; 9 | int m,n; 10 | 11 | while(0 5 | #include 6 | using namespace std; 7 | int main(){ 8 | int t;scanf("%d",&t); 9 | while(t--){ 10 | int n;scanf("%d",&n); 11 | 12 | vector> v(n); 13 | 14 | map x; 15 | map y; 16 | int temp; 17 | 18 | for(int i=0;i>temp; 20 | v[i].push_back(temp);x[temp]++; 21 | cin>>temp; 22 | v[i].push_back(temp);y[temp]++; 23 | } 24 | long long int minus=0; 25 | for(int i=0;i 3 | #include 4 | using namespace std; 5 | 6 | int main() { 7 | int n, m; 8 | //input size of array 1 and array 2 9 | cin>>n>>m; 10 | 11 | int arr1[n],arr2[m]; 12 | //creating a set to store distinct values 13 | sets; 14 | 15 | for(int i=0;i>arr1[i]; 17 | s.insert(arr1[i]); 18 | } 19 | 20 | for(int i=0;i>arr2[i]; 22 | s.insert(arr2[i]); 23 | } 24 | //displaying elements of set i.e., union of the two arrays 25 | for(auto i:s) 26 | cout< 2 | using namespace std; 3 | typedef long long ll; 4 | 5 | ll z[2000005]; 6 | 7 | int main() { 8 | string s; 9 | cin>>s; 10 | ll n=s.size(); 11 | 12 | for (ll i = 1, l = 0, r = 0; i < n; ++i) { 13 | if (i <= r) 14 | z[i] = min (r - i + 1, z[i - l]); 15 | while (i + z[i] < n && s[z[i]] == s[i + z[i]]) 16 | ++z[i]; 17 | if (i + z[i] - 1 > r) 18 | l = i, r = i + z[i] - 1; 19 | } 20 | 21 | for(ll i=1;i" 36 | 37 | Path_Sum(root.left,summ + root.data,path) 38 | 39 | Path_Sum(root.right,summ + root.data,path) 40 | Path_Sum(root1,0,'') -------------------------------------------------------------------------------- /Binary_Tree_Using_Python/sum_of_left_leaf_node.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | 3 | def __init__(self,data): 4 | 5 | self.data = data 6 | self.left = None 7 | self.right = None 8 | 9 | 10 | root1 = Node(3) 11 | 12 | root1.left = Node(5) 13 | 14 | root1.right = Node(1) 15 | root1.left.left = Node(6) 16 | 17 | root1.left.right = Node(2) 18 | root1.left.right.left = Node(4) 19 | 20 | 21 | 22 | def SumOf_left_leaf(root,left): 23 | 24 | if root == None: 25 | return 0 26 | 27 | if root.left == None and root.right == None and left : 28 | # print(root.data) 29 | 30 | return root.data 31 | 32 | l = SumOf_left_leaf(root.left,True) 33 | 34 | r = SumOf_left_leaf(root.right,False) 35 | 36 | return l+r 37 | 38 | ans = [] 39 | print(SumOf_left_leaf(root1,False)) 40 | 41 | -------------------------------------------------------------------------------- /Binary_Tree_Using_Python/univalued_BT.py: -------------------------------------------------------------------------------- 1 | 2 | class Node: 3 | 4 | def __init__(self,data): 5 | 6 | self.data= data 7 | self.left = None 8 | self.right = None 9 | 10 | 11 | root = Node(1) 12 | 13 | root.left = Node(1) 14 | root.right = Node(1) 15 | 16 | root.left.left = Node(1) 17 | root.left.right = Node(1) 18 | 19 | root.right.right = Node(0) 20 | 21 | 22 | def IsUnivalued(root,unival): 23 | 24 | if root == None: 25 | return True 26 | 27 | if root.data != unival: 28 | return False 29 | 30 | return IsUnivalued(root.left,unival) and IsUnivalued(root.right,unival) 31 | 32 | print(IsUnivalued(root,root.data)) 33 | 34 | -------------------------------------------------------------------------------- /CSES Problem Set/Building Roads.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void dfs(int n,map> &adj,vector &v){ 5 | v[n]=1; 6 | for(auto i:adj[n]){ 7 | if(v[i]==-1) dfs(i,adj,v); 8 | } 9 | } 10 | 11 | int main(){ 12 | int n,m; cin>>n>>m; 13 | map> adj; 14 | while (m--) 15 | { 16 | int a,b; cin>>a>>b; 17 | adj[a].push_back(b); 18 | adj[b].push_back(a); 19 | } 20 | vector v(n+1,-1); 21 | vector ans; 22 | for (int i = 1; i <= n; i++) 23 | { 24 | if(v[i]==-1){ 25 | ans.push_back(i); 26 | dfs(i,adj,v); 27 | } 28 | } 29 | cout< 2 | using namespace std; 3 | #define endl "\n" 4 | #define int long long 5 | #define MOD (int)(1e9+7) 6 | 7 | int c[101],dp[1000100]; 8 | int n,x; 9 | 10 | int rec(int v){ 11 | if(v<0)return 0; 12 | if(v==0)return 1; 13 | if(dp[v]!=-1)return dp[v]; 14 | int vall=0; 15 | for(int i=0;i>n>>x; 22 | for(int i=0;i>c[i]; 23 | for(int i=0;i<=x;i++)dp[i]=-1; 24 | int ans=rec(x); 25 | cout<>_t;while(_t--) 34 | solve(); 35 | } 36 | -------------------------------------------------------------------------------- /CSES Problem Set/Dynamic Programming/Coin Combinations II.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define endl "\n" 4 | #define int long long 5 | #define MOD (int)(1e9+7) 6 | 7 | int c[110],dp[1000010]; 8 | int n,x; 9 | 10 | void solve(){ 11 | cin>>n>>x; 12 | memset(dp,0,sizeof(dp)); 13 | for(int i=0;i>c[i]; 15 | dp[0]=1; 16 | for(int i=0;i0) 19 | (dp[j+c[i]]+=dp[j])%=MOD; 20 | cout<>_t;while(_t--) 29 | solve(); 30 | } 31 | -------------------------------------------------------------------------------- /CSES Problem Set/Dynamic Programming/Dice Combinations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define endl "\n" 4 | #define int long long 5 | #define MOD (int)(1e9+7) 6 | 7 | void solve(){ 8 | int n;cin>>n; 9 | int sum=1,val=2,stp=1,sum_taken=1; 10 | vector sarray={0,0,0,0,0,1}; 11 | while(val<=n){ 12 | stp=0; 13 | if(val<=6)stp=1; 14 | (stp+=sum)%=MOD; 15 | sum=stp; 16 | for(int i=0;i<5;i++){ 17 | sarray[i]=sarray[i+1]; 18 | sum+=sarray[i]; 19 | } 20 | sarray[5]=stp; 21 | val++; 22 | } 23 | cout<>_t;while(_t--) 32 | solve(); 33 | } 34 | -------------------------------------------------------------------------------- /CSES Problem Set/Dynamic Programming/Grid Paths.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define endl "\n" 4 | #define int long long 5 | #define MOD (int)(1e9+7) 6 | 7 | int dp[1010][1010]; 8 | char gd[1010][1010]; 9 | int n; 10 | 11 | int rec(int x,int y){ 12 | if(x>n||y>n)return 0; 13 | if(gd[x][y]=='*')return 0; 14 | if(x==n&&y==n)return 1; 15 | if(dp[x][y]!=-1)return dp[x][y]; 16 | return dp[x][y]=(rec(x+1,y)+rec(x,y+1))%MOD; 17 | } 18 | 19 | void solve(){ 20 | cin>>n; 21 | for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)cin>>gd[i][j]; 22 | memset(dp,-1,sizeof(dp)); 23 | cout<>_t;while(_t--) 32 | solve(); 33 | } 34 | -------------------------------------------------------------------------------- /CSES Problem Set/Dynamic Programming/Increasing Subsequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define pb push_back 4 | #define inf 1e18 5 | #define mp make_pair 6 | #define mod 1000000007 7 | typedef vector vi; 8 | typedef long long int lli; 9 | typedef pair pii; 10 | long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } 11 | long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } 12 | int main(){ 13 | ios_base::sync_with_stdio(false); 14 | cin.tie(NULL); 15 | int n,ans=0; 16 | cin>>n; 17 | vi c(n); 18 | for(int i=0;i>c[i]; 19 | vi dp; 20 | 21 | for(int i=0;i 2 | using namespace std; 3 | #define pb push_back 4 | #define inf 1e18 5 | #define mp make_pair 6 | typedef vector vi; 7 | typedef long long int lli; 8 | typedef pair pii; 9 | int main(){ 10 | ios_base::sync_with_stdio(false); 11 | cin.tie(NULL); 12 | int n; 13 | cin>>n; 14 | vi cost(n),dp(1e5+1,0); 15 | dp[0]=1; 16 | for(int &u:cost)cin>>u; 17 | for(int j=0;j=0;i--) 19 | dp[i]=dp[i]||dp[i-cost[j]]; 20 | vi s; 21 | for(int i=1;i<=1e5;i++) 22 | if(dp[i]) s.pb(i); 23 | cout< 2 | using namespace std; 3 | #define pb push_back 4 | #define inf 1e18 5 | #define mod 1000000007 6 | #define mp make_pair 7 | typedef vector vi; 8 | typedef long long int lli; 9 | typedef pair pii; 10 | int main(){ 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | int n; 14 | cin>>n; 15 | lli mx=n*(n+1)/2; 16 | if(mx%2==1){ 17 | cout<<0;return 0; 18 | } 19 | vectordp(mx+1,0); 20 | dp[0]=1; 21 | for(int i=1;i<=n;i++){ 22 | for(int j=mx/2-i;j>=0;j--){ 23 | dp[j+i]=(dp[j+i]+dp[j])%(1000000007); 24 | } 25 | } 26 | cout<<(((dp[mx/2])%mod)*(500000004%mod))%mod; 27 | return 0; 28 | } -------------------------------------------------------------------------------- /CSES Problem Set/Dynamic Programming/dicecombinationsyogmanamit.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | const int mod = 1e9+7; 5 | const int N = 1e6+7; 6 | 7 | int dp[N] = {}; 8 | 9 | int32_t main() 10 | { 11 | int n; cin >> n; 12 | int k = 7; 13 | dp[0] = 1; 14 | for(int i = 0; i= N-1 ? 1 : 0; 20 | 21 | // Time complexity - O(n) becuase of for loop; 22 | // Space complexity - O(1) as no extra space is used; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /CSES Problem Set/Graph/Planet Queries I.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define pb push_back 4 | #define inf 1e18 5 | #define mp make_pair 6 | typedef vector vi; 7 | typedef long long int lli; 8 | typedef pair pii; 9 | vectorp; 10 | int main(){ 11 | ios_base::sync_with_stdio(false); 12 | cin.tie(NULL); 13 | 14 | int n,m; 15 | cin>>n>>m; 16 | p.resize(31,vector(n+1)); 17 | for(int i=1;i<=n;i++) cin>>p[0][i]; 18 | for(int k=1;k<=30;k++) for(int i=1;i<=n;i++)p[k][i]=p[k-1][p[k-1][i]]; 19 | while(m--){ 20 | int d=-1; 21 | int now,k; 22 | cin>>now>>k; 23 | while(k!=0){ 24 | d++; 25 | if(1&(k)){ 26 | now=p[d][now]; 27 | 28 | } 29 | k=(k>>1); 30 | } 31 | cout< 2 | using namespace std; 3 | int main(){ 4 | int n; 5 | cin>>n; 6 | int a[n]; 7 | for(int i = 0; i < n; i++){ 8 | cin>>a[i]; 9 | } 10 | long long int moves = 0; 11 | for(int i = 1; i < n; i++){ 12 | if(a[i]-a[i-1] < 0){ 13 | moves = moves + a[i-1] - a[i]; 14 | a[i] = a[i-1]; 15 | } 16 | } 17 | cout< 2 | using namespace std; 3 | #define ll long long int 4 | 5 | void solve() 6 | { 7 | ll n,q; 8 | cin>>n>>q; 9 | vectora(n); 10 | for(int i=0;i>a[i]; 13 | } 14 | vector pre(n,0);//build a prefix array 15 | pre[0]=a[0]; 16 | for(ll i=1;i>s>>e; 25 | s-=1;e-=1; 26 | if(s==0) 27 | { 28 | cout<>t; 41 | t=1; 42 | while(t--) 43 | solve(); 44 | } 45 | -------------------------------------------------------------------------------- /Codeforces Problems/116A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define int long long 4 | #define endl "\n" 5 | 6 | 7 | int32_t main(){ 8 | int t,mx=INT_MIN; 9 | cin>>t; 10 | int r = 0; 11 | while(t--){ 12 | int a ,b; 13 | cin>>a>>b; 14 | r = r-a+b; 15 | mx = max(mx,r); 16 | 17 | } 18 | cout< 2 | using namespace std; 3 | 4 | int main(){ 5 | string s; 6 | cin>>s; 7 | 8 | for(int i = 0 ; i = 'A' && s[i] <= 'Z'){ 10 | s[i] += 32; 11 | } 12 | if(s[i] != 'a' &&s[i] != 'y' &&s[i] != 'e' &&s[i] != 'i' &&s[i] != 'o' &&s[i] != 'u'){ 13 | cout<<'.'< 2 | using namespace std; 3 | 4 | int main(){ 5 | int n; 6 | cin>>n; 7 | 8 | if(n%744 == 0 ||n%747==0 || n%47 == 0 ||n % 477 == 0 ||n%474==0 || n%4 ==0 || n%7 == 0){ 9 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | int n, k; 6 | cin>>n>>k; 7 | int *arr = new int[n]; 8 | for(int i=0; i>arr[i]; 10 | int limit=arr[k-1], ans=0; 11 | 12 | for(int i=0; i=limit && arr[i]!=0) 14 | ans++; 15 | else 16 | break; 17 | } 18 | 19 | cout< 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int n,k; 8 | cin>>n>>k; 9 | int arr[n],count=0; 10 | for(int i=0;i>arr[i];} 11 | for(int i=0;i=arr[k-1]&&(arr[i]>0)) count++; 13 | else break; 14 | } 15 | cout< 2 | using namespace std; 3 | #define ll long long 4 | #define endl "\n" 5 | 6 | void solve() 7 | { 8 | ll n; 9 | cin >> n; 10 | cout << (long long)(-n + 1) << ' ' << (long long)(n) << '\n'; 11 | } 12 | 13 | int main() 14 | { 15 | 16 | ios_base ::sync_with_stdio(false); 17 | cin.tie(NULL); 18 | 19 | int T; 20 | cin >> T; 21 | while (T--) 22 | solve(); 23 | return 0; 24 | } -------------------------------------------------------------------------------- /Codeforces Problems/1594B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define ll long long 4 | #define endl "\n" 5 | const ll INF = 1e9 + 7; 6 | 7 | void solve() 8 | { 9 | ll n, k; 10 | cin >> n >> k; 11 | ll p = 1; 12 | ll ans = 0; 13 | for (int i = 0; i < 31; i++) 14 | { 15 | if (k & (1 << i)) 16 | { 17 | ans = (ans + p) % INF; 18 | // cout << "ans-> " << ans << " " << (1 << i) << " "; 19 | // cout << "p-> " << p << " "; 20 | } 21 | p *= n; 22 | p %= INF; 23 | } 24 | cout << ans << '\n'; 25 | } 26 | 27 | int main() 28 | { 29 | 30 | ios_base ::sync_with_stdio(false); 31 | cin.tie(NULL); 32 | 33 | int T; 34 | cin >> T; 35 | while (T--) 36 | solve(); 37 | return 0; 38 | } -------------------------------------------------------------------------------- /Codeforces Problems/1692A - Marathon.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() { 6 | int t; 7 | cin>>t; 8 | 9 | while(t--) { 10 | int a, b, c, d; 11 | cin>>a>>b>>c>>d; 12 | int count = 0; 13 | 14 | if(b>a) 15 | count++; 16 | if(c>a) 17 | count++; 18 | if(d>a) 19 | count++; 20 | 21 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int n; 6 | cin>>n; 7 | int arr[1000][1000]; 8 | int total = 0; 9 | 10 | for(int i=0; i>arr[i][j]; 14 | if(arr[i][j]==1) 15 | c++; 16 | } 17 | if(c>1) 18 | total ++; 19 | } 20 | 21 | cout< 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | string user_name; 8 | cin>>user_name; 9 | sort(user_name.begin(), user_name.end()); 10 | 11 | for(int i=0; user_name[i]!='\0';) { 12 | if(user_name[i] == user_name[i+1]) 13 | user_name.erase (user_name.begin() + i); 14 | else 15 | i++; 16 | } 17 | 18 | int size = user_name.size(); 19 | if(size&1) 20 | cout<<"IGNORE HIM!"; 21 | else 22 | cout<<"CHAT WITH HER!"; 23 | 24 | return 0; 25 | } -------------------------------------------------------------------------------- /Codeforces Problems/263A - Beautiful Matrix.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int matrix[5][5]; 7 | // Variables to store the location of '1' 8 | int one_i=0, one_j=0; 9 | 10 | // Inputting the matrix 11 | for(int i=0; i<5; i++) { 12 | for(int j=0; j<5; j++) { 13 | cin>>matrix[i][j]; 14 | if(matrix[i][j]) { 15 | one_i = i+1; 16 | one_j = j+1; 17 | } 18 | } 19 | } 20 | 21 | int count = 0; 22 | count += abs(one_i-3); 23 | count += abs(one_j-3); 24 | 25 | cout< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | 8 | int T,x=0;cin>>T; 9 | string s; 10 | for(int i=0;i>s; 12 | if(s[1]=='-'){x--;} 13 | else x++; 14 | } 15 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int w; 6 | cin>>w; 7 | 8 | if(w%2 || w==2) 9 | cout<<"NO"; 10 | else 11 | cout<<"YES"; 12 | 13 | return 0; 14 | } -------------------------------------------------------------------------------- /Codeforces Problems/50A - Domino piling.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int m, n; 6 | cin>>m>>n; 7 | cout<<(m*n)/2; 8 | return 0; 9 | } -------------------------------------------------------------------------------- /Codeforces Problems/50A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main(){ 6 | 7 | int m,n;cin>>m>>n; 8 | cout<-1: 27 | ans=min(ans,left[i-1]+right[i]) 28 | print(ans if ans!=float("inf") else 0) -------------------------------------------------------------------------------- /Codeforces Problems/71A - Way Too Long Words.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | using namespace std; 4 | 5 | int main() { 6 | int n; 7 | cin>>n; 8 | 9 | while(n--) { 10 | string str; 11 | cin>>str; 12 | int size = str.length(); 13 | if(size>10) { 14 | int i=1; 15 | while(str[i] != '\0') 16 | i++; 17 | cout< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | float a,b,c,p,q,r; 7 | cin>>t; 8 | while(t--) 9 | { 10 | cin>>a>>b>>c>>p>>q>>r; 11 | double ans=(p+q+r)/2; 12 | if((a+b+c)>ans || (p+b+c)>ans || (a+q+c)>ans || (a+b+r)>ans) 13 | { 14 | cout<<"YES"< 10 | using namespace std; 11 | 12 | int main() { 13 | int tc,b; 14 | cin>>tc; 15 | while(tc!=0){ 16 | int b; 17 | cin>>b; 18 | b=b-2; 19 | b=b/2; 20 | b=(b*(b+1))/2; 21 | cout< 2 | using namespace std; 3 | int facto(int p){ 4 | int ans = 1; 5 | for(int i = p;p>=2;p--){ 6 | ans *= p; 7 | } 8 | return ans; 9 | } 10 | int check(vectorv, int m){ 11 | // mC2*4!/4 = m!/ 12 | int ans,fans; 13 | ans = facto(m)/(facto(m-2)*2); 14 | fans = ans*6; 15 | return fans; 16 | 17 | } 18 | int main(){ 19 | int t; 20 | cin>>t; 21 | while(t--){ 22 | int n; 23 | cin>>n; 24 | vectorv(n); 25 | for(int i=0;i>v[i]; 27 | } 28 | cout< 2 | using namespace std; 3 | int check(int arr[],int n){ 4 | sort(arr, arr+n); 5 | for(int i=0;i>t; 15 | while(t--){ 16 | int n; 17 | cin>>n; 18 | int arr[n]; 19 | for(int i=0;i>arr[i]; 21 | } 22 | if(check(arr,n)) 23 | cout<<"yes"< 2 | using namespace std; 3 | 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--){ 8 | int a,b,c; 9 | cin>>a>>b>>c; 10 | 11 | if( (a+b==c)|| (a+c==b)||(b+c==a)) 12 | cout<<"yes"< 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin >> t; 7 | for(int i=0;i> n; 12 | if(n<=6) 13 | { 14 | time = 15; 15 | } 16 | else if(n%2==0) 17 | { 18 | time = (n*5)/2; 19 | } 20 | else 21 | { 22 | time = ((n+1)*5)/2; 23 | } 24 | cout << time << endl; 25 | } 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Codeforces Problems/sort_zero.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | int t;cin>>t; 8 | while(t--) 9 | { 10 | 11 | int n;cin>>n; 12 | int a[n]; 13 | for(int i=0;i>a[i]; 15 | int pos=n-1; 16 | while(pos>0&&a[pos]>=a[pos-1]) pos--; 17 | map m; 18 | for(int i=0;i s; 26 | for(int i=0;i<=in;i++) 27 | s.insert(a[i]); 28 | cout< 2 | using namespace std; 3 | 4 | 5 | int helper(vector>& tri, int i, int j, vector>& dp){ 6 | int n = tri.size() ; 7 | 8 | for(int j = 0; j < n; j++ ){ 9 | dp[n-1][j] = tri[n-1][j] ; 10 | } 11 | 12 | for(int i = n-2; i >= 0; i--){ 13 | for(int j = i; j >= 0; j-- ){ 14 | dp[i][j] = tri[i][j] + max(dp[i+1][j] , dp[i+1][j+1]) ; 15 | } 16 | } 17 | 18 | return dp[0][0] ; 19 | 20 | 21 | } 22 | 23 | 24 | int maxSumPath(vector>& tri) { 25 | int n = tri.size() ; 26 | 27 | vector> dp(n, vector(n, -1) ) ; 28 | 29 | return helper(tri, 0, 0, dp) ; 30 | } 31 | 32 | 33 | int main() 34 | { 35 | vector > tri{ { 1 }, 36 | { 2, 1 }, 37 | { 3, 3, 2 } }; 38 | cout << maxSumPath(tri); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /Floyd_Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void printFloydTriangle(int n) 5 | { 6 | int i, j, val = 1; 7 | for (i = 1; i <= n; i++) 8 | { 9 | for (j = 1; j <= i; j++) 10 | cout << val++ << " "; 11 | cout << endl; 12 | } 13 | } 14 | 15 | int main() 16 | { 17 | printFloydTriangle(6); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /GFG/Kadanes_Algorithm.cpp: -------------------------------------------------------------------------------- 1 | public: 2 | // arr: input array 3 | // n: size of array 4 | //Function to find the sum of contiguous subarray with maximum sum. 5 | long long maxSubarraySum(int arr[], int n){ 6 | 7 | // Your code here 8 | long long int max_sum=arr[0],res=arr[0]; 9 | for(int i=1;i (arr[i]+max_sum)) ?arr[i]: (arr[i]+max_sum); 11 | res= (res> max_sum) ?res: max_sum; 12 | } 13 | return res; 14 | 15 | } 16 | }; 17 | 18 | 19 | // Question - https://practice.geeksforgeeks.org/problems/kadanes-algorithm-1587115620/1 20 | -------------------------------------------------------------------------------- /Google Kickstart 2022 Round G Walktober.py: -------------------------------------------------------------------------------- 1 | def solution(t): 2 | m, n, p = map(int, input().split()) 3 | lst = [] 4 | for i in range(m): 5 | lst.append(list(map(int, input().split()))) 6 | 7 | steps = 0 8 | for i in range(n): 9 | max = lst[p-1][i] 10 | for j in range(m): 11 | if max < lst[j][i]: 12 | max = lst[j][i] 13 | steps = steps + max - lst[p-1][i] 14 | 15 | print("case #{0}: {1}".format(t+1, steps)) 16 | 17 | test = int(input()) 18 | for x in range(test): 19 | solution(x) 20 | -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/BFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/BFS.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Creating_And_displaying_a_graph.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Creating_And_displaying_a_graph.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_BFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_BFS.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_DFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_Detection_in_undirected_graph_DFS.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_Directed_graph_DFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_Directed_graph_DFS.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_directed_graph_BFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Cycle_detection_in_directed_graph_BFS.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/DFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/DFS.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Search_in_a_maze.cpp: -------------------------------------------------------------------------------- 1 | // Coded By Shreyash Shrivastava 2 | 3 | #include 4 | using namespace std; 5 | 6 | int main(){ 7 | return 0; 8 | } -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Topological_Sort_DFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Topological_Sort_DFS.exe -------------------------------------------------------------------------------- /Graphs questions from Love Babbar SDE sheet/Topological_sort_BFS.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/Graphs questions from Love Babbar SDE sheet/Topological_sort_BFS.exe -------------------------------------------------------------------------------- /Jump Game: -------------------------------------------------------------------------------- 1 | The problem can be think of as if you walk into i, how many available steps you have? 2 | if you have 0 steps left while the current value is 0, then you won't be able to go to the next step. 3 | 4 | The the question is how to calculate the current step, it is: 5 | max(--nlen,nums[i]) 6 | since we reuse nlen, so I write it into two steps. 7 | 8 | 9 | class Solution { 10 | public: 11 | bool canJump(vector& nums) { 12 | int n = nums.size(); 13 | if ( n == 1 ) return true; 14 | 15 | int nlen = nums[0]; 16 | 17 | for ( int i = 1; i 2 | using namespace std; 3 | 4 | int max(int a, int b); 5 | int lcs( char *X, char *Y, int m, int n ) 6 | { 7 | if (m == 0 || n == 0) 8 | return 0; 9 | if (X[m-1] == Y[n-1]) 10 | return 1 + lcs(X, Y, m-1, n-1); 11 | else 12 | return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n)); 13 | } 14 | 15 | int max(int a, int b) 16 | { 17 | return (a > b)? a : b; 18 | } 19 | 20 | int main() 21 | { 22 | char X[] = "AGGTAB"; 23 | char Y[] = "GXTXAYB"; 24 | 25 | int m = strlen(X); 26 | int n = strlen(Y); 27 | 28 | cout<<"Length of Longest Common Subsequence is "<< lcs( X, Y, m, n ) ; 29 | 30 | return 0; 31 | } 32 | -------------------------------------------------------------------------------- /Leetcode Easy/ContainsDuplicate.java: -------------------------------------------------------------------------------- 1 | import java.util.HashSet; 2 | import java.util.Set; 3 | 4 | public class ContainsDuplicate { 5 | 6 | public static boolean containsDuplicate(int[] nums) { 7 | 8 | Set unique = new HashSet(); 9 | 10 | for (int i = 0; i < nums.length; i++) { 11 | unique.add(nums[i]); 12 | } 13 | 14 | if (unique.size() == nums.length) 15 | return false; 16 | return true; 17 | 18 | } 19 | 20 | public static void main(String args[]) { 21 | int numbers[] = { 1, 2, 2, 3 }; 22 | 23 | if (containsDuplicate(numbers)) { 24 | System.out.println("Duplicates present"); 25 | } else 26 | System.out.println("Duplicates not present"); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Leetcode Easy/Divide_Array_Into_Equal_Pairs.java: -------------------------------------------------------------------------------- 1 | // Link to the problem:https://leetcode.com/problems/divide-array-into-equal-pairs/ 2 | 3 | class Solution { 4 | public boolean divideArray(int[] nums) { 5 | int[] count=new int[501]; 6 | for(int i:nums){ 7 | count[i]++; 8 | } 9 | for(int i:count){ 10 | if((i&1)==1){ 11 | return false; 12 | } 13 | } 14 | return true; 15 | } 16 | } -------------------------------------------------------------------------------- /Leetcode Easy/InvertedBinaryTree.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Definition for a binary tree node. 3 | * struct TreeNode { 4 | * int val; 5 | * TreeNode *left; 6 | * TreeNode *right; 7 | * TreeNode() : val(0), left(nullptr), right(nullptr) {} 8 | * TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} 9 | * TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} 10 | * }; 11 | */ 12 | class Solution { 13 | public: 14 | TreeNode* invertTree(TreeNode* root) { 15 | if(root==NULL){ 16 | return NULL; 17 | } 18 | else{ 19 | TreeNode* l=invertTree(root->left); 20 | TreeNode* r=invertTree(root->right); 21 | 22 | root->left=r; 23 | root->right=l; 24 | } 25 | return root; 26 | 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /Leetcode Easy/Leetcode.java: -------------------------------------------------------------------------------- 1 | \// java function to return true if contain duplicate 2 | public boolean containsDuplicate(int[] nums) { 3 | Arrays.sort(nums); 4 | for(int i=0;i<=nums.length-2;i++) 5 | { 6 | if(nums[i]==nums[i+1]) 7 | return true; 8 | } 9 | return false; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /Leetcode Easy/LongestCommonPrefix.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | 3 | public class LongestCommonPrefix { 4 | 5 | public static String longestCommonPrefix(String[] strs) { 6 | 7 | Arrays.sort(strs); 8 | 9 | int count = 0; 10 | 11 | String first = strs[0]; 12 | String last = strs[strs.length - 1]; 13 | 14 | while (count < first.length()) { 15 | if (first.charAt(count) == last.charAt(count)) 16 | count++; 17 | else 18 | break; 19 | } 20 | 21 | return count == 0 ? "" : first.substring(0, count); 22 | 23 | } 24 | 25 | public static void main(String args[]) { 26 | String strs[] = { "flower", "flow", "flight" }; 27 | System.out.println(longestCommonPrefix(strs)); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /Leetcode Easy/Powe Of Three.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | bool isPowerOfThree(int n) { 4 | long long temp= 1; 5 | while(temp<= n){ 6 | if(n== temp){ 7 | return true; 8 | } 9 | temp*= 3; 10 | } 11 | return false; 12 | } 13 | }; 14 | -------------------------------------------------------------------------------- /Leetcode Easy/RemoveElement.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeElement(vector& nums, int val) { 4 | int n = nums.size(); 5 | int j = 0; 6 | for(int i = 0; i List[int]: 3 | freq = Counter(nums) 4 | ans = [-1, -1] 5 | for x in range(1, len(nums) + 1): 6 | if x not in freq: 7 | ans[1] = x 8 | if freq[x] > 1: 9 | ans[0] = x 10 | return ans -------------------------------------------------------------------------------- /Leetcode Easy/SingleNumber.java: -------------------------------------------------------------------------------- 1 | //problem link: https://leetcode.com/problems/single-number/ 2 | 3 | class Solution { 4 | public int singleNumber(int[] nums) { 5 | int sum = 0; 6 | for (int i = 0; i val!=ptr2->val) 25 | return false; 26 | return isMirror(ptr1->left,ptr2->right)&&isMirror(ptr1->right,ptr2->left); 27 | } 28 | bool isSymmetric(struct TreeNode* root){ 29 | if(!root) 30 | return true; 31 | return isMirror(root->left,root->right); 32 | } 33 | -------------------------------------------------------------------------------- /Leetcode Easy/reverse_linked_list.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | ListNode* reverseList(ListNode* head) { 4 | ListNode *nextNode, *prevNode = NULL; 5 | while (head) { 6 | nextNode = head->next; 7 | head->next = prevNode; 8 | prevNode = head; 9 | head = nextNode; 10 | } 11 | return prevNode; 12 | } 13 | }; -------------------------------------------------------------------------------- /Leetcode Easy/twosum.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int[] twoSum(int[] nums, int target) { 3 | int[] answer = new int[2]; 4 | for (int i = 0 ; i < nums.length - 1 ; i ++) { 5 | for (int j = i + 1; j < nums.length; j++) { 6 | if(nums[i] + nums[j] == target) { 7 | answer[0] = i; 8 | answer[1] = j; 9 | return answer; 10 | } 11 | } 12 | } 13 | return answer; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Leetcode Problems/136. Single Number.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public int singleNumber(int[] nums) { 3 | Map lol = new TreeMap(); 4 | for(int i : nums){ 5 | if(lol.containsKey(i)) lol.put(i, lol.get(i)+1); 6 | else lol.put(i, 1); 7 | } 8 | for(int i : lol.keySet()){ 9 | if(lol.get(i)==1) return i; 10 | } 11 | return 0; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Leetcode Problems/39.Combination_sum.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void sum(int ind,int target,vector&arr,vector>&ans,vector&ds){ 4 | if(ind==arr.size()){ 5 | if(target==0){ 6 | ans.push_back(ds); 7 | } 8 | return; 9 | } 10 | //if we decide to pick up the element we need to check 11 | if(arr[ind]<=target){ 12 | ds.push_back(arr[ind]); 13 | sum(ind,target-arr[ind],arr,ans,ds); 14 | ds.pop_back(); //when u comeback make sure to pop this element 15 | } 16 | sum(ind+1,target,arr,ans,ds); 17 | 18 | } 19 | 20 | 21 | 22 | vector> combinationSum(vector& candidates, int target) { 23 | vector>ans; 24 | vectords; 25 | sum(0,target,candidates,ans,ds); 26 | return ans; 27 | } 28 | }; 29 | -------------------------------------------------------------------------------- /Leetcode Problems/3Sum Closest: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int threeSumClosest(vector& nums, int target) { 4 | sort(nums.begin(),nums.end()); 5 | int ans=nums[0]+nums[1]+nums[2]; 6 | 7 | for(int i=0;itarget) e--; 17 | else s++; 18 | } 19 | } 20 | return ans; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /Leetcode Problems/75. Sort_color.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void sortColors(vector& nums) { 4 | int low=0, high=nums.size()-1, mid=0; 5 | while(mid<=high){ 6 | if(nums[mid]==1){ 7 | mid++; 8 | } 9 | else if(nums[mid]==0){ 10 | swap(nums[low],nums[mid]); 11 | low++; 12 | mid++; 13 | 14 | } 15 | else if(nums[mid]==2){ 16 | swap(nums[high],nums[mid]); 17 | high--; 18 | 19 | } 20 | } 21 | 22 | } 23 | }; 24 | -------------------------------------------------------------------------------- /Leetcode Problems/91. Decode_ways.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | //tjis is top down approach 4 | vectordp; 5 | int numDecodings(string s) { 6 | dp.assign(s.size(),-1); 7 | return nways(0,s); 8 | } 9 | int nways(int i,string s){ 10 | if(i>=s.size())return 1; 11 | else if(s[i]=='0') return 0; //case consider "0" 12 | else if(i==s.size()-1)return 1; 13 | else if (dp[i] != -1) 14 | return dp[i]; //memo 15 | // 0-9 0-6 16 | else if(s[i]=='1'||(s[i]=='2' && (s[i+1]>='0'&&s[i+1]<='6'))){ 17 | return dp[i] = nways(i+1,s)+nways(i+2,s); 18 | // this shows that there are two ways or two choices 19 | } 20 | else return dp[i] = nways(i+1,s); 21 | // if first indes is greater than 2 22 | 23 | 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Leetcode Problems/Binary-Search704.java: -------------------------------------------------------------------------------- 1 | package com.company; 2 | //binary search easy leetcode question number 704; 3 | public class BinarySearch704 { 4 | public static void main(String[] args) { 5 | int [] nums = {-1,0,3,5,9,12}; 6 | int target = 9; 7 | int ans = search(nums ,target); 8 | System.out.println(ans); 9 | } 10 | public int search(int[] nums, int target) { 11 | int start = 0; 12 | int end = nums.length -1; 13 | 14 | while(start <= end){ 15 | int mid = start + (end - start)/2; 16 | if (target nums[mid]){ 19 | start = mid +1; 20 | }else { 21 | return mid; 22 | } 23 | 24 | } 25 | return -1; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Leetcode Problems/ClimbingStairs.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Leetcode - 70 Climbing Stairs 3 | You are climbing a staircase. It takes n steps to reach the top. 4 | Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 5 | */ 6 | class Solution { 7 | public: 8 | int climbStairs(int n) { 9 | int dp[n+1];//cause of the base cases we take n+1 10 | //bottom up approach 11 | dp[0]=1; //ways to climb 0steps is 1 i.e no climbing 12 | dp[1]=1;//ways to climb 1 steps is 1 i.e by taking 1 step 13 | //for the rest of the stairs 14 | for(int i=2; i<=n;i++) 15 | { 16 | dp[i]=dp[i-1]+dp[i-2]; 17 | //current step will be the sum of previous 2 steps 18 | //dp[2]=dp[1]+dp[0] 19 | } 20 | return dp[n]; 21 | } 22 | }; 23 | -------------------------------------------------------------------------------- /Leetcode Problems/Count ans Say.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string countAndSay(int n) { 4 | string str = "1"; 5 | 6 | for(int i=2; i<=n; i++) { 7 | int idx = 0; 8 | char toMatch = str[0]; 9 | string next = ""; 10 | while(idx < str.size()) { 11 | int freq = 0; 12 | while(str[idx] == toMatch) { 13 | freq++; 14 | idx++; 15 | } 16 | next += to_string(freq) + toMatch; 17 | if(idx >= str.size()) 18 | break; 19 | toMatch = str[idx]; 20 | } 21 | str = next; 22 | } 23 | return str; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Leetcode Problems/Divide Intervals Into Minimum Number of Groups.cpp: -------------------------------------------------------------------------------- 1 | int minGroups(vector>& nums) { 2 | int n = INT_MIN; 3 | for(int i=0;i v(n+2, 0); 7 | for(int i=0;i& nums) { 13 | vector freq; 14 | freq.resize(nums.size()+1); 15 | int i; 16 | for(i=0;i<=nums.size()+1;++i){ 17 | freq[nums[i]]++; 18 | if(freq[nums[i]]==2){ 19 | break; 20 | } 21 | } 22 | 23 | return nums[i]; 24 | } 25 | }; 26 | -------------------------------------------------------------------------------- /Leetcode Problems/Find_the_Index_of_the_First_Occurrence_in_a_String.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def strStr(self, haystack: str, needle: str) -> int: 3 | if needle in haystack: 4 | return haystack.index(needle) 5 | else: 6 | return -1 7 | 8 | ## Question - https://leetcode.com/problems/find-the-index-of-the-first-occurrence-in-a-string 9 | 10 | 11 | ''' Example 1: 12 | 13 | Input: haystack = "sadbutsad", needle = "sad" 14 | Output: 0 15 | Explanation: "sad" occurs at index 0 and 6. 16 | The first occurrence is at index 0, so we return 0. 17 | Example 2: 18 | 19 | Input: haystack = "leetcode", needle = "leeto" 20 | Output: -1 21 | Explanation: "leeto" did not occur in "leetcode", so we return -1. ''' 22 | -------------------------------------------------------------------------------- /Leetcode Problems/IntegerToRoman.cpp: -------------------------------------------------------------------------------- 1 | // 12. Integer to Roman (Medium) 2 | /* 3 | Example 1 4 | Input: 3 5 | Output: "III" 6 | Explanation: 3 is represented as 3 ones. 7 | 8 | Example 2 9 | Input: 58 10 | Output: "LVIII" 11 | Explanation: L = 50, V = 5, III = 3. 12 | 13 | Example 3 14 | Input: 1994 15 | Output: "MCMXCIV" 16 | Explanation: M = 1000, CM = 900, XC = 90 and IV = 4. 17 | */ 18 | 19 | class Solution { 20 | public: 21 | string intToRoman(int num) { 22 | string ans = ""; 23 | string nos[]={"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; 24 | int val[] = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1}; 25 | for(int i = 0; num > 0; i++){ 26 | while(num >= val[i]){ 27 | num -= val[i]; 28 | ans += nos[i]; 29 | } 30 | } 31 | return ans; 32 | } 33 | }; 34 | -------------------------------------------------------------------------------- /Leetcode Problems/Longest Palindromic Substring.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string longestPalindrome(string s) { 4 | int n=s.length(); 5 | int maxLength=1; 6 | int start=0; 7 | int low,high; 8 | for(int i=0;i=0 && s[i]==s[low]){ 12 | low--; 13 | } 14 | while(high=0 && highmaxLength){ 23 | maxLength=length; 24 | start=low+1; 25 | } 26 | } 27 | return s.substr(start,maxLength); 28 | 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /Leetcode Problems/LongestRepeatingSubsequence.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | using namespace std; 4 | 5 | int main() 6 | { 7 | string str; 8 | cin>>str; 9 | int n = str.length(); 10 | vector> dp(n+1, vector(n+1,0)); 11 | 12 | for(int i=1; i<=n; i++) 13 | { 14 | for(int j=1; j<=n; j++) 15 | { 16 | if(i!=j and str[i-1]==str[j-1]) 17 | dp[i][j] = 1+dp[i-1][j-1]; 18 | else 19 | dp[i][j] = max(dp[i-1][j], dp[i][j-1]); 20 | } 21 | } 22 | cout<=0 and r=0 and c int: 17 | area_max = 0 18 | for i in range(len(grid)): 19 | for j in range(len(grid[0])): 20 | if(grid[i][j]==1): 21 | area_max = max(area_max, self.cal(grid, i, j)) 22 | return area_max 23 | -------------------------------------------------------------------------------- /Leetcode Problems/Median_of_two_sorted_array.c: -------------------------------------------------------------------------------- 1 | /* num1 and num2 are two sorted arrays of size m and n respectively, 2 | return the median of the two sorted arrays. 3 | */ 4 | 5 | double findMedianSortedArrays(int* nums1, int nums1Size, int* nums2, int nums2Size){ 6 | int size=nums1Size+nums2Size; 7 | double nums3[size]; 8 | int i=0,j=0,k=0; 9 | for(;i& neededTime) { 4 | int cost=0; 5 | int n=colors.size(),i=0,j=1; 6 | for(int k=0;kneededTime[j]){ 9 | cost+=neededTime[j]; 10 | j++; 11 | } 12 | else{ 13 | cost+=neededTime[i]; 14 | i=j; 15 | j++; 16 | } 17 | } 18 | else{ 19 | i=j; 20 | j++; 21 | } 22 | } 23 | 24 | return cost; 25 | } 26 | }; -------------------------------------------------------------------------------- /Leetcode Problems/MoveZeros.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void moveZeroes(vector& nums) { 4 | int left=0; 5 | int n=nums.size(); 6 | 7 | for(int i=0;i str: 4 | ans=int(num1)*int(num2) 5 | return str(ans) 6 | 7 | 8 | #Question - https://leetcode.com/problems/multiply-strings/description/ 9 | -------------------------------------------------------------------------------- /Leetcode Problems/NextPermutation.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | void nextPermutation(vector& nums) { 4 | int n=nums.size(); 5 | if(n==1){ 6 | return; 7 | } 8 | int i=1; 9 | int lastInc=-1; 10 | while(inums[i-1]) 12 | lastInc=i; 13 | i+=1; 14 | } 15 | if(lastInc==-1){ 16 | for(i=0;inums[lastInc-1] and nums[i] mp; 7 | int high=0, cnt=0; 8 | 9 | while(highnext){ 14 | len++; 15 | temp = temp -> next; 16 | } 17 | 18 | //go till kth node 19 | temp -> next = head; 20 | k = k % len; 21 | k = len - k; 22 | while(k--) temp = temp -> next; 23 | 24 | //make node head & break connection 25 | head = temp -> next; 26 | temp -> next = NULL; 27 | return head; 28 | } 29 | 30 | 31 | //Time Complexity: O(n) 32 | //Space Complexity: O(1) 33 | -------------------------------------------------------------------------------- /Leetcode Problems/Rotate_list.c: -------------------------------------------------------------------------------- 1 | //You are given the head of a linked list, reverse the list and return the reversed list 2 | 3 | /* 4 | Example : 5 | Input : head = [1,2,3,4,5] 6 | Output : [5,4,3,2,1] 7 | */ 8 | 9 | /* 10 | Definition for singly-linked list. 11 | struct ListNode { 12 | int val; 13 | struct ListNode *next; 14 | }; 15 | */ 16 | 17 | 18 | struct ListNode* reverseList(struct ListNode* head){ 19 | struct ListNode *prev,*cur,*next; 20 | prev=NULL; 21 | cur=head; 22 | while(cur!=NULL) 23 | { 24 | next=cur->next; 25 | cur->next=prev; 26 | prev=cur; 27 | cur=next; 28 | } 29 | return prev; 30 | } 31 | -------------------------------------------------------------------------------- /Leetcode Problems/Running sum of 1d array.c: -------------------------------------------------------------------------------- 1 | //You are asked to define the running sum of the array and return it 2 | 3 | /* 4 | Example : 5 | Input : nums=[1,2,3,4,5] 6 | Output : [1,3,6,10,15] 7 | 8 | Explanation : Running sum is obtained as follows : [1, 1+2, 1+2+3, 1+2+3+4, 1+2+3+4+5] 9 | */ 10 | 11 | int* runningSum(int* nums, int numsSize, int* returnSize){ 12 | *returnSize=numsSize; 13 | int* res=(int *)malloc(sizeof(int)*numsSize); 14 | res[0]=nums[0]; 15 | for(int i=1;i singleNumber(vector& nums) { 4 | vectoranswer; 5 | unordered_mapmap; 6 | for(auto i:nums) 7 | { 8 | map[i]++; 9 | } 10 | for(auto i:map) 11 | { 12 | if(i.second == 1) 13 | { 14 | answer.push_back(i.first); 15 | } 16 | } 17 | return answer; 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /Leetcode Problems/SlidingWindowMaximum.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class Solution { 5 | public: 6 | vector maxSlidingWindow(vector& nums, int k) { 7 | vector res; 8 | queue q; 9 | int i=0,j=0; 10 | 11 | while(j0 && q.front()>& rectangle) { 4 | 5 | } 6 | 7 | void updateSubrectangle(int row1, int col1, int row2, int col2, int newValue) { 8 | 9 | } 10 | 11 | int getValue(int row, int col) { 12 | 13 | } 14 | }; 15 | 16 | /** 17 | * Your SubrectangleQueries object will be instantiated and called as such: 18 | * SubrectangleQueries* obj = new SubrectangleQueries(rectangle); 19 | * obj->updateSubrectangle(row1,col1,row2,col2,newValue); 20 | * int param_2 = obj->getValue(row,col); 21 | */ 22 | -------------------------------------------------------------------------------- /Leetcode Problems/SumofLeftLeaves.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int ans=0; 4 | int sumOfLeftLeaves(TreeNode* root) { 5 | 6 | if(root!=NULL) 7 | { 8 | if(root->left != NULL && root->left->left == NULL && root->left->right == NULL) 9 | { 10 | ans+=root->left->val; 11 | } 12 | sumOfLeftLeaves(root->left); 13 | sumOfLeftLeaves(root->right); 14 | } 15 | return ans; 16 | } 17 | }; 18 | -------------------------------------------------------------------------------- /Leetcode Problems/TwoInputSum2.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | vector twoSum(vector& numbers, int target) { 4 | unordered_mapa; 5 | vectorres; 6 | for(int i=0;i 'Node': 4 | return copy.deepcopy(node) -------------------------------------------------------------------------------- /Leetcode Problems/container_with_most_water.cpp: -------------------------------------------------------------------------------- 1 | int Solution::maxArea(vector &A) 2 | { 3 | int n = A.size(); 4 | int mx = 0; 5 | int i = 0, j = n - 1; 6 | while (i < j) 7 | { 8 | if (A[i] < A[j]) 9 | { 10 | mx = max(mx, A[i] * (j - i)); 11 | i++; 12 | } 13 | else 14 | { 15 | mx = max(mx, A[j] * (j - i)); 16 | j--; 17 | } 18 | } 19 | return mx; 20 | } 21 | -------------------------------------------------------------------------------- /Leetcode Problems/generate_parenthesis.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void addingpar(vector &v, string str, int n, int m) { 5 | if (n == 0 && m == 0) { 6 | v.push_back(str); 7 | return; 8 | } 9 | if (m > 0) { addingpar(v, str + ")", n, m - 1); } 10 | if (n > 0) { addingpar(v, str + "(", n - 1, m + 1); } 11 | } 12 | 13 | vector generateParenthesis(int n) { 14 | vector res; 15 | addingpar(res, "", n, 0); 16 | return res; 17 | } 18 | 19 | int main() 20 | { 21 | int n; 22 | cin>>n; 23 | 24 | vector v = generateParenthesis(n); 25 | 26 | for(int i=0;i &a, int si, vector &dp) 5 | { 6 | // top-down approach 7 | if (si >= a.size()) 8 | return 0; 9 | 10 | if (dp[si] != -1) 11 | return dp[si]; 12 | int include = a[si] + helper(a, si + 2, dp); 13 | int exclude = helper(a, si + 1, dp); 14 | dp[si] = max(include, exclude); 15 | 16 | return max(include, exclude); 17 | } 18 | int rob(vector &nums) 19 | { 20 | int n = nums.size(); 21 | vector dp(n + 1, -1); 22 | return helper(nums, 0, dp); 23 | } 24 | }; -------------------------------------------------------------------------------- /Leetcode Problems/house_robber_2.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int rob(vector &nums) 5 | { 6 | // bottom-up approach 7 | int n = nums.size(); 8 | vector dp1(n); 9 | vector dp2(n); 10 | dp1[0] = nums[0]; 11 | if (n == 1) 12 | return dp1[0]; 13 | dp2[0] = nums[1]; 14 | dp1[1] = max(nums[0], nums[1]); 15 | if (n == 2) 16 | return dp1[1]; 17 | dp2[1] = max(nums[1], nums[2]); 18 | for (int i = 2; i < n - 1; i++) 19 | { 20 | dp1[i] = max(nums[i] + dp1[i - 2], dp1[i - 1]); 21 | } 22 | for (int i = 2; i < n - 1; i++) 23 | { 24 | dp2[i] = max(nums[i + 1] + dp2[i - 2], dp2[i - 1]); 25 | } 26 | return max(dp1[n - 2], dp2[n - 2]); 27 | } 28 | }; -------------------------------------------------------------------------------- /Leetcode Problems/longest_increasing_subsequence.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int lengthOfLIS(vector &nums) 5 | { 6 | int n = nums.size(); 7 | if (n == 0) 8 | return 0; 9 | vector v; 10 | v.push_back(nums[0]); 11 | for (int i = 1; i < n; i++) 12 | { 13 | if (nums[i] > v.back()) 14 | v.push_back(nums[i]); 15 | else 16 | { 17 | int idx = lower_bound(v.begin(), v.end(), nums[i]) - v.begin(); 18 | v[idx] = nums[i]; 19 | } 20 | } 21 | return v.size(); 22 | } 23 | }; -------------------------------------------------------------------------------- /Leetcode Problems/maximumsubarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxSubArray(vector& nums) { 4 | int ans=nums[0],maxi=nums[0]; 5 | for(int i=1;i str: 3 | digits = [(1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"), (90, "XC"), (50, "L"), (40, "XL"), 4 | (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I")] 5 | 6 | ans = "" 7 | for n, s in digits: # Maximum 13 operations 8 | while num >= n: # Each while loop, maximum 3 operations, imagine case num=3 9 | ans += s 10 | num -= n 11 | return ans -------------------------------------------------------------------------------- /Leetcode Problems/medium/25. Reverse Nodes in k-Group.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | # class ListNode: 3 | # def __init__(self, val=0, next=None): 4 | # self.val = val 5 | # self.next = next 6 | class Solution: 7 | def reverseKGroup(self, head: ListNode, k: int) -> ListNode: 8 | prev=None 9 | temp=head 10 | for i in range(k): 11 | if temp==None: 12 | return head 13 | temp=temp.next 14 | temp=head 15 | for i in range(k): 16 | curr=temp 17 | temp=temp.next 18 | curr.next=prev 19 | prev=curr 20 | head.next=self.reverseKGroup(temp,k) 21 | return prev 22 | -------------------------------------------------------------------------------- /Leetcode Problems/medium/692 Top K Frequent Words.py: -------------------------------------------------------------------------------- 1 | # Todo import Counter 2 | class Solution: 3 | def topKFrequent(self, words: List[str], k: int) -> List[str]: 4 | x=list(Counter(words).items()) 5 | x.sort(key=lambda x:(-x[1],x[0])) 6 | return [x[i][0] for i in range(k)] -------------------------------------------------------------------------------- /Leetcode Problems/medium/House_Robber.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int House_Robber(vector& nums) { 5 | int a=0,b=0; 6 | for(int i=0;i nums; 17 | int n,a; 18 | cin>>n; 19 | for(int i=0;i>a; 21 | nums.push_back(a); 22 | } 23 | cout< int: 3 | count=0 4 | n=len(nums) 5 | i=0 6 | while True: 7 | hold=nums[i] 8 | idx=i 9 | maximum=-1 10 | if idx>=n-1: 11 | return count 12 | for j in range(i+1,i+hold+1): 13 | if j>=n-1: 14 | return count+1 15 | if maximum 2 | 3 | using namespace std; 4 | 5 | int jump(vector& nums) { 6 | int len=nums.size()-1, curr=-1, next=0, ans=0; 7 | 8 | for(int i=0; nextcurr) 11 | ans++, curr=next; 12 | next=max(next, nums[i]+i); 13 | } 14 | return ans; 15 | } 16 | 17 | int main() 18 | { 19 | vector arr{2,3,1,1,4}; 20 | cout<next==NULL) 14 | return NULL; 15 | while(temp!=NULL) 16 | { 17 | i++; 18 | temp=temp->next; 19 | } 20 | if(i==n) 21 | return head->next; 22 | i=i-n-1; 23 | temp=head; 24 | while(i>0) 25 | { 26 | i--; 27 | temp=temp->next; 28 | } 29 | temp->next=temp->next->next; 30 | return head; 31 | } 32 | -------------------------------------------------------------------------------- /Leetcode Problems/medium/Swap_nodes_in_pairs.c: -------------------------------------------------------------------------------- 1 | //You are given a linked list, you have to swap every two adjacent nodes and return its head 2 | 3 | /* 4 | Definition for singly-linked list. 5 | struct ListNode { 6 | int val; 7 | struct ListNode *next; 8 | }; 9 | */ 10 | 11 | 12 | struct ListNode* swapPairs(struct ListNode* head){ 13 | if(!head||!head->next) 14 | return head; 15 | struct ListNode* temp=head->next; 16 | head->next=swapPairs(head->next->next); 17 | temp->next=head; 18 | return temp; 19 | } 20 | -------------------------------------------------------------------------------- /Leetcode Problems/medium/course-schedule.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canFinish(self, numCourses: int, prerequisites: List[List[int]]) -> bool: 3 | self.adj=[None]*numCourses 4 | for i in range(numCourses): 5 | self.adj[i]=[] 6 | 7 | for i in prerequisites: 8 | self.adj[i[0]].append(i[1]) 9 | 10 | self.visited=[0]*numCourses 11 | for i in range(numCourses): 12 | if self.visited[i]==0 and not self.dfs(i): 13 | return False 14 | 15 | return True 16 | 17 | def dfs(self,v): 18 | if self.visited[v]==1: 19 | return False 20 | 21 | self.visited[v]=1 22 | 23 | for i in self.adj[v]: 24 | if not self.dfs(i): 25 | return False 26 | 27 | self.visited[v]=2 28 | 29 | return True -------------------------------------------------------------------------------- /Leetcode Problems/medium/image Overlap.py: -------------------------------------------------------------------------------- 1 | def largestOverlap(self, A, B): 2 | N = len(A) 3 | LA = [i / N * 100 + i % N for i in xrange(N * N) if A[i / N][i % N]] 4 | LB = [i / N * 100 + i % N for i in xrange(N * N) if B[i / N][i % N]] 5 | c = collections.Counter(i - j for i in LA for j in LB) 6 | return max(c.values() or [0]) -------------------------------------------------------------------------------- /Leetcode Problems/medium/jump-game.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def canJump(self, nums: List[int]) -> bool: 3 | mr=0 4 | #n=len(nums) 5 | if len(nums)==1: 6 | return True 7 | for i in range(len(nums)): 8 | if (i+nums[i]>mr): 9 | mr=i+nums[i] 10 | if i==mr: 11 | break 12 | return mr>=len(nums)-1 -------------------------------------------------------------------------------- /Leetcode Problems/medium/minimum-path-sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def minPathSum(self, grid: List[List[int]]) -> int: 3 | h=len(grid) 4 | w=len(grid[0]) 5 | if h==0: 6 | return 0 7 | for i in range(1,w): 8 | grid[0][i]+=grid[0][i-1] 9 | 10 | for i in range(1,h): 11 | for j in range(w): 12 | if j==0: 13 | grid[i][j]+=grid[i-1][j] 14 | else: 15 | grid[i][j]+=min(grid[i-1][j],grid[i][j-1]) 16 | return grid[h-1][w-1] -------------------------------------------------------------------------------- /Leetcode Problems/medium/palindrome-partitioning.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def partition(self, s): 3 | def find_all_palindromes(s): 4 | B = [0] * (2*n) 5 | for i, j in combinations_with_replacement(range(n), 2): 6 | if s[i:j+1] == s[i:j+1][::-1]: 7 | B[i+j+1] = max(B[i+j+1], j-i+1) 8 | return B 9 | 10 | n = len(s) 11 | B = find_all_palindromes(s) 12 | 13 | dp = [[] for _ in range(n+1)] 14 | dp[0] = [[]] 15 | for i in range(0, n): 16 | for k in range(0, i+1): 17 | if B[2*i-k+1] >= k: 18 | for elem in dp[i-k]: 19 | dp[i + 1].append(elem + [s[i-k:i+1]]) 20 | 21 | return dp[-1] -------------------------------------------------------------------------------- /Leetcode Problems/medium/reverseInteger.java: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public static int reverse(int x) { 3 | String temp = String.valueOf(x); 4 | String[] arr = new String[temp.length()]; 5 | for(int i = 0; i < temp.length(); i++){ 6 | if(!String.valueOf(temp.charAt(i)).equals("-")){ 7 | arr[temp.length()-i-1] = String.valueOf(temp.charAt(i)); 8 | } 9 | } 10 | String st = ""; 11 | for(String digit : arr){ 12 | if(digit!=null) st+=digit; 13 | } 14 | int num = 0; 15 | try{ 16 | num = Integer.valueOf(st); 17 | } catch(NumberFormatException e){ 18 | return 0; 19 | } 20 | if(x < 0) num = num*=-1; 21 | return num; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Leetcode Problems/medium/unique-binary-search-trees.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def numTrees(self, n: int) -> int: 3 | if n<2: 4 | return 1 5 | s=[0]*(n+1) 6 | s[0]=1 7 | s[1]=1 8 | for i in range(2,n+1): 9 | for j in range(0,i): 10 | s[i]+=s[j]*s[i-j-1] 11 | 12 | return s[-1] -------------------------------------------------------------------------------- /Leetcode Problems/medium/zigzag-conversion.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | class Solution: 3 | def convert(self, s: str, numRows: int) -> str: 4 | arr=list(range(numRows)) 5 | ans=defaultdict(list) 6 | for i in range(numRows-2,0,-1): 7 | arr.append(i) 8 | l=len(arr) 9 | for i in range(len(s)): 10 | x=i%l 11 | ans[arr[x]].append(s[i]) 12 | p="" 13 | for i in range(numRows): 14 | p+="".join(ans[i]) 15 | return p -------------------------------------------------------------------------------- /Leetcode Problems/missingpositiveno.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | // r is size 4 | int findMissingNumber(int *arr, int r){ 5 | int missing_no= r; 6 | for(int i=0;i=0;i--) 15 | { 16 | rmax[i] = max(arr[i],rmax[i+1]); 17 | } 18 | for(int i=1;i<=n-1;i++) 19 | { 20 | res = res+(min(lmax[i],rmax[i])-arr[i]); 21 | } 22 | return res; 23 | } 24 | }; 25 | -------------------------------------------------------------------------------- /Leetcode Problems/rain_water_trapped.cpp: -------------------------------------------------------------------------------- 1 | int Solution::trap(const vector &A) { 2 | int n = A.size(); 3 | int ans = 0; 4 | int h = 0, l = 0, r = n - 1; 5 | while (l <= r) 6 | { 7 | if (A[l] <= A[r]) 8 | { 9 | if (h > A[l]) 10 | ans += h - A[l++]; 11 | else 12 | h = A[l++]; 13 | } 14 | else 15 | { 16 | if (h > A[r]) 17 | ans += h - A[r--]; 18 | else 19 | h = A[r--]; 20 | } 21 | } 22 | return ans; 23 | } 24 | -------------------------------------------------------------------------------- /Leetcode Problems/removeduplicatesfromasortedarray.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int removeDuplicates(vector& nums) { 4 | 5 | 6 | int count = 0; 7 | 8 | for(int i = 1;inext; 13 | b = A; 14 | for(int i = 1; i < C; i++) 15 | b = b->next; 16 | if(B == 1) 17 | { 18 | c = A; 19 | A = b; 20 | } 21 | else 22 | { 23 | c = a->next; 24 | a->next = b; 25 | } 26 | d = c; 27 | ListNode *n = c->next; 28 | while(c != b) 29 | { 30 | ListNode *t = n->next; 31 | n->next = c; 32 | c = n; 33 | n = t; 34 | } 35 | d->next = n; 36 | return A; 37 | } 38 | -------------------------------------------------------------------------------- /Leetcode Problems/searchinsertposition.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int searchInsert(vector& nums, int target) { 4 | int idx=0; 5 | while(idxnums[idx])idx++; 6 | return idx; 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /Leetcode Problems/stock_buy_and_sell.cpp: -------------------------------------------------------------------------------- 1 | int maxProfit(int price[],int n) 2 | { 3 | int profit = 0; 4 | for(int i=1;iprice[i-1]) 7 | { 8 | profit += (price[i]-price[i-1]); 9 | } 10 | } 11 | return profit; 12 | -------------------------------------------------------------------------------- /Leetcode Problems/stockyBuySell.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | int maxProfit(vector& prices) { 4 | int ans = 0; 5 | int minPrice = INT_MAX; 6 | 7 | for(int i = 0; i 2 | #include 3 | using namespace std; 4 | class Solution{ 5 | public: 6 | vector twoSum(vector& nums, int target){ 7 | vector v; 8 | bool flag = false; 9 | for(int i=0;i 2 | using namespace std; 3 | 4 | int maximumSegments(int n, int a, 5 | int b, int c) 6 | { 7 | 8 | int dp[n + 1]; 9 | 10 | memset(dp, -1, sizeof(dp)); 11 | 12 | dp[0] = 0; 13 | 14 | for (int i = 0; i < n; i++) 15 | { 16 | if (dp[i] != -1) { 17 | 18 | 19 | if(i + a <= n ) 20 | dp[i + a] = max(dp[i] + 1, 21 | dp[i + a]); 22 | 23 | if(i + b <= n ) 24 | dp[i + b] = max(dp[i] + 1, 25 | dp[i + b]); 26 | 27 | if(i + c <= n ) 28 | dp[i + c] = max(dp[i] + 1, 29 | dp[i + c]); 30 | } 31 | } 32 | return dp[n]; 33 | } 34 | 35 | 36 | int main() 37 | { 38 | int n = 7, a = 5, b = 2, c = 5; 39 | cout << maximumSegments(n, a, b, c); 40 | return 0; 41 | } 42 | -------------------------------------------------------------------------------- /Minimum Bit Flips to Convert Number: -------------------------------------------------------------------------------- 1 | // C++ program for minimum bit flips to convert number 2 | #include 3 | using namespace std; 4 | 5 | // Function that count set bits 6 | int countSetBits(int n) 7 | { 8 | int count = 0; 9 | while (n > 0) { 10 | count++; 11 | n &= (n - 1); 12 | } 13 | return count; 14 | } 15 | 16 | // Function that return count of 17 | // flipped number 18 | int FlippedCount(int a, int b) 19 | { 20 | // Return count of set bits in 21 | // a XOR b 22 | return countSetBits(a ^ b); 23 | } 24 | 25 | // Driver code 26 | int main() 27 | { 28 | int a = 10; 29 | int b = 20; 30 | 31 | // Function call 32 | cout << FlippedCount(a, b) << endl; 33 | return 0; 34 | } 35 | 36 | 37 | -------------------------------------------------------------------------------- /PrepBytes_CP Problems/BoxesandToys.cpp: -------------------------------------------------------------------------------- 1 | //Question Link- https://mycode.prepbytes.com/problems/fundamentals/BOXTOY 2 | 3 | #include 4 | using namespace std; 5 | int main() 6 | { 7 | int box=0; 8 | int n; 9 | cin>>n; 10 | for(int i=0;i>t>>c; 15 | if(c-t>=2) 16 | { 17 | box++; 18 | } 19 | } 20 | cout< 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int n; 9 | cin>>n; 10 | for(int i=0;i>num; 14 | int sum=0; 15 | for(int j=1;j 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | int num; 9 | cin>>num; 10 | int reverse=0; 11 | while(num!=0) 12 | { 13 | reverse=num%10; 14 | num=num/10; 15 | cout< 4 | using namespace std; 5 | long long M,R1,R2,R3; 6 | int main() 7 | { 8 | int t; 9 | cin>>t; 10 | while(t--) 11 | { 12 | cin>>M>>R1>>R2>>R3; 13 | M%=4; 14 | if(M==0) 15 | cout<<0< 4 | using namespace std; 5 | 6 | int main() 7 | { 8 | for (int i = 2; i <= 6; i++) 9 | { 10 | for (int j = 1; j < 6; j++) 11 | { 12 | if (i > j) 13 | { 14 | cout << j; 15 | } 16 | else 17 | cout << " "; 18 | } 19 | for (int j = 5; j >= 1; j--) 20 | { 21 | if (j < i) 22 | cout < 3 | using namespace std; 4 | int main(){ 5 | int t; 6 | cin>>t; 7 | while(t--) 8 | { 9 | int n; 10 | cin>>n; 11 | int arr[n]; 12 | for(int i=0;i>arr[i]; 15 | } 16 | int minele=INT_MAX; 17 | int maxele=0; 18 | for(int i=0;i0) 12 | { 13 | int a[]=new int[6]; 14 | for(int x=0;x<6;x++) 15 | { 16 | a[x]=sc.nextInt(); 17 | } 18 | int sum1=a[0]+a[1]+a[2]; 19 | int sum2=a[3]+a[4]+a[5]; 20 | if(sum1>sum2) 21 | System.out.println("1"); 22 | else 23 | System.out.println("2"); 24 | t--; 25 | } 26 | } 27 | catch(Exception e) 28 | { 29 | return; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Problems Python/Knapsack.py: -------------------------------------------------------------------------------- 1 | def knapSack(W, wt, val, n): 2 | K = [[0 for x in range(W + 1)] for x in range(n + 1)] 3 | 4 | # Build table K[][] in bottom up manner 5 | for i in range(n + 1): 6 | for w in range(W + 1): 7 | if i == 0 or w == 0: 8 | K[i][w] = 0 9 | elif wt[i-1] <= w: 10 | K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]) 11 | else: 12 | K[i][w] = K[i-1][w] 13 | 14 | return K[n][W] 15 | 16 | # Driver program to test above function 17 | val = [60, 100, 120] 18 | wt = [10, 20, 30] 19 | W = 50 20 | n = len(val) 21 | print(knapSack(W, wt, val, n)) -------------------------------------------------------------------------------- /Problems Python/factorial.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | for i in range(tc): 4 | a = int(input()) 5 | factorial = 1 6 | for j in range(1,a+1): 7 | factorial = factorial*j 8 | print(factorial) 9 | except: 10 | pass -------------------------------------------------------------------------------- /Problems Python/gcd_lcm.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | while t>0: 4 | a,b = map(int, input().split()) 5 | mul = a*b 6 | while(b%a!=0): 7 | r = b%a 8 | b = a 9 | a = r 10 | print(a, mul//a) 11 | 12 | 13 | 14 | except: 15 | pass -------------------------------------------------------------------------------- /Problems Python/guesser.py: -------------------------------------------------------------------------------- 1 | from random import randrange 2 | n = randrange(1000) 3 | while True: 4 | v = int(input()) 5 | if v == n: 6 | print('you Win!') 7 | break 8 | print('Smaller' if (n 0): 7 | if (D - A - B - C) >= 0: 8 | print(1) 9 | D = 0 10 | elif (D - A - B) >= 0 or (D - A - C) >= 0 or (D - B - C) >= 0: 11 | print(2) 12 | D = 0 13 | else: 14 | print(3) 15 | D = 0 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Random Problems/Josephus_problem.cpp: -------------------------------------------------------------------------------- 1 | class Solution 2 | { 3 | public: 4 | int josephus(int n, int k) 5 | { 6 | queue q; 7 | for(int i=1;i<=n;i++) 8 | q.push(i); 9 | 10 | int c = 0; 11 | while(q.size()!=1) 12 | { 13 | int x = q.front(); 14 | c++; 15 | q.pop(); 16 | if(c%k!=0) 17 | q.push(x); 18 | // cout< List[int]: 2 | for i, val in enumerate(nums): 3 | first_index = i 4 | sec_num = target - val 5 | if sec_num in nums[i+1:] : 6 | return first_index,nums.index(sec_num,i+1) 7 | -------------------------------------------------------------------------------- /codechef problems/April Long One 2022(APRIL221D )/Dazzling_AXNODR_Challenge.cpp: -------------------------------------------------------------------------------- 1 | #include "bits/stdc++.h" 2 | using namespace std; 3 | int main() 4 | { 5 | int t; 6 | cin >> t; 7 | while (t--) 8 | { 9 | long long int n; 10 | cin>>n; 11 | if(n==1) 12 | { 13 | cout<<1< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | 8 | int T;cin>>T; 9 | for(int i=0;i>n>>p>>k; 12 | int ans; 13 | int re=(n-1)%k; 14 | int x=p%k; 15 | int a = (n-1-re)/k; 16 | if(x>=0&&x<=re){ans= x*(a+1) + (p-x)/k +1 ;} 17 | else ans= (a+1)*(re+1) + (x-re-1)*a + (p-x)/k+1; 18 | 19 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | // your code goes here 6 | int t,n; 7 | cin>>t; 8 | while(t--) 9 | { 10 | long long x=1,y=2,s=0; 11 | cin>>n; 12 | if(n==1) s=1; 13 | else if(n==2) s=2; 14 | for(int i=3;i<=n;i++) 15 | { 16 | s=x+y; 17 | x=y; 18 | y=s; 19 | } 20 | cout< 2 | using namespace std; 3 | const int n = 1e6+5; 4 | int arr[n]; 5 | void solve () 6 | { 7 | int n; 8 | cin>>n; 9 | string str; 10 | cin>>str; 11 | size_t found = str.find("LL"); 12 | size_t found1 = str.find("RR"); 13 | if (found != string::npos) {cout << "YES" << endl;} 14 | else if (found1 != string::npos) { 15 | cout << "YES" << endl; 16 | }else{ 17 | cout<<"NO"<>t; 25 | for(int i = 0; i 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n, a[1000]; 10 | cin>>n; 11 | 12 | for(int i=0; i>a[i]; 14 | 15 | int temp = n-1; 16 | 17 | while(a[temp] == 0) 18 | temp--; 19 | 20 | cout<next != NULL) { 14 | head = head->next->next; 15 | temp = temp->next; 16 | } 17 | 18 | int ans = temp->val; 19 | return ans; 20 | } 21 | -------------------------------------------------------------------------------- /codechef problems/DSAPREP_08 - Linked List/RTLL.cpp: -------------------------------------------------------------------------------- 1 | /*struct Node { 2 | int data; 3 | struct Node* next; 4 | Node(int data) 5 | { 6 | this->data = data; 7 | next = NULL; 8 | } 9 | };*/ 10 | 11 | Node* reverseList(Node* head) { 12 | Node* prev = NULL; 13 | Node* curr = head; 14 | 15 | while(curr != NULL) { 16 | head = curr->next; 17 | curr->next = prev; 18 | prev = curr; 19 | curr = head; 20 | } 21 | 22 | return prev; 23 | } -------------------------------------------------------------------------------- /codechef problems/EQLZING.cpp: -------------------------------------------------------------------------------- 1 | // Problem Link: https://www.codechef.com/LTIME111D/problems/EQLZING 2 | 3 | #include 4 | using namespace std; 5 | #define ll long long int 6 | #define pb push_back 7 | #define pp pop_back 8 | #define Vec vector 9 | const long long int MOD = 1e9+7; 10 | 11 | void solve(){ 12 | int x,y; 13 | cin>>x>>y; 14 | if(x == y){ 15 | cout<<"Yes"<<"\n"; 16 | }else{ 17 | int def = abs(x - y); 18 | if((def & 1) != 0){ 19 | cout<<"No"<<"\n"; 20 | }else{ 21 | cout<<"Yes"<<"\n"; 22 | } 23 | } 24 | } 25 | int main() 26 | { 27 | ios_base::sync_with_stdio(false); 28 | cin.tie(NULL); 29 | int t; 30 | cin>>t; 31 | while(t--){ 32 | solve(); 33 | } 34 | return 0; 35 | } -------------------------------------------------------------------------------- /codechef problems/HIGHSCORE.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n, a, b, c, d; 10 | cin>>n; 11 | cin>>a>>b>>c>>d; 12 | 13 | if(a>=b && a>=c && a>=d && a<=n) 14 | cout<=a && b>=c && b>=d && b<=n) 16 | cout<=a && c>=b && c>=d && c<=n) 18 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int x, y; 10 | cin>>x>>y; 11 | if(y>=x && y<=x+200) 12 | cout<<"YES\n"; 13 | else 14 | cout<<"NO\n"; 15 | } 16 | 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /codechef problems/June Cook-Off 2022 (COOK142D)/BREAKSTICK.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | long long n, x; 10 | cin>>n>>x; 11 | 12 | if(x%2) 13 | cout<<"YES\n"; 14 | else { 15 | if((n-x)%2==0) 16 | cout<<"YES\n"; 17 | else 18 | cout<<"NO\n"; 19 | } 20 | } 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /codechef problems/June Cook-Off 2022 (COOK142D)/FIRSTANDLAST.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n, arr[100000]; 10 | cin>>n; 11 | for(int i=0; i>arr[i]; 13 | 14 | int max = arr[0] + arr[n-1]; 15 | 16 | for(int i=0; imax) 19 | max = temp; 20 | } 21 | 22 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int a, b; 10 | cin>>a>>b; 11 | int f=0; 12 | int cnt=0; 13 | 14 | for(int i=a; i<=b; i++) { 15 | int s=i; 16 | int q=i+1; 17 | int p=i+2; 18 | int r=i+3; 19 | 20 | if((s^q^p^r)==0 && r<=b) { 21 | f=1; 22 | cout< 10) 27 | break; 28 | } 29 | } 30 | 31 | if(f==0) 32 | cout<<-1< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n, x; 10 | cin>>n>>x; 11 | cout<<(n/(x*3))< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int a, b; 10 | cin>>a>>b; 11 | int temp = (b-a)%3; 12 | if(temp==2) 13 | cout<<"NO\n"; 14 | else 15 | cout<<"YES\n"; 16 | } 17 | 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /codechef problems/June Long One 2022 (JUNE221D)/CHAIRS_.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int x, y; 10 | cin>>x>>y; 11 | if(x>y) 12 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int a, b, n, count=0; 10 | cin>>a>>b; 11 | n = abs(a-b); 12 | for(int i=1; i<=sqrt(n); i++) { 13 | if(n%i == 0) { 14 | if(n/i == i) 15 | count++; 16 | else 17 | count += 2; 18 | } 19 | } 20 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n; 10 | cin>>n; 11 | int *ans = new int[n]; 12 | int temp = n; 13 | for(int i=n-1; i>=0; i-=2) 14 | ans[i] = temp--; 15 | for(int i=n-2, c=1; i>=0; i-=2, c++) 16 | ans[i] = c; 17 | for(int i=0; i 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n, step=0; 10 | string str1, str2; 11 | cin>>n; 12 | cin>>str1>>str2; 13 | for(int i=0; i 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n, x; 10 | cin>>n>>x; 11 | int temp = n/6; 12 | if(n > temp*6) 13 | temp += 1; 14 | cout<next != NULL) { 14 | head = head->next->next; 15 | temp = temp->next; 16 | } 17 | 18 | int ans = temp->val; 19 | return ans; 20 | } 21 | -------------------------------------------------------------------------------- /codechef problems/May Cook-Off 2022 (COOK141D)/CGYM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int x, y, z; 10 | cin>>x>>y>>z; 11 | 12 | if(x+y <= z) 13 | cout<<"2"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int x, y; 10 | cin>>x>>y; 11 | 12 | if((x*100) >= (y*10)) 13 | cout<<"Cloth"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int x,y; 10 | cin>>x>>y; 11 | 12 | if(y <= (x*1.07)) 13 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int x,y; 10 | cin>>x>>y; 11 | 12 | if(x==y && (x>0 && y>0)) 13 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n; 10 | cin>>n; 11 | 12 | // Since after spending 20%, 20% and 30%, the remaining profit is 30% -> 15 coins per sale 13 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int x, a, b; 6 | cin>>x>>a>>b; 7 | if(a+b <= x) 8 | cout<<"YES"< 2 | using namespace std; 3 | 4 | int main() { 5 | int x, y; 6 | cin>>x>>y; 7 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int n, d[1000], count=0; 10 | cin>>n; 11 | 12 | for(int i=0; i>d[i]; 14 | if(d[i] >= 1000) 15 | count++; 16 | } 17 | 18 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int w, x, y, z; 10 | cin>>w>>x>>y>>z; 11 | 12 | if((w + (y*z)) == x) 13 | cout<<"FILLED"< x) 15 | cout<<"OVERFLOW"< 2 | #include 3 | 4 | using namespace std; 5 | 6 | int main(){ 7 | 8 | int T;cin>>T; 9 | for(int i=0;i>g1>>s1>>b1>>g2>>s2>>b2; 12 | int sum1=g1+s1+b1; 13 | int sum2=g2+s2+b2; 14 | if(sum1>sum2) cout<<"1"< 2 | using namespace std; 3 | 4 | int main() { 5 | int a[4], count=0; 6 | 7 | for(int i=0; i<4; i++) { 8 | cin>>a[i]; 9 | if(a[i] >= 10) 10 | count++; 11 | } 12 | cout< 2 | using namespace std; 3 | 4 | int main() { 5 | int t; 6 | cin>>t; 7 | 8 | while(t--) { 9 | int x, y; 10 | cin>>x>>y; 11 | cout<<(x*10)+(y*90)< 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | int main(){ 8 | 9 | int T;cin>>T; 10 | for(int i=0;i>a[j];} 13 | sort(a,a+4); 14 | if(a[0]==a[3]) cout<<0<data = data; 7 | next = NULL; 8 | } 9 | };*/ 10 | 11 | Node* reverseList(Node* head) { 12 | Node* prev = NULL; 13 | Node* curr = head; 14 | 15 | while(curr != NULL) { 16 | head = curr->next; 17 | curr->next = prev; 18 | prev = curr; 19 | curr = head; 20 | } 21 | 22 | return prev; 23 | } -------------------------------------------------------------------------------- /codechef problems/add.py: -------------------------------------------------------------------------------- 1 | try: 2 | n = int(input()) 3 | for i in range(n): 4 | A,B = map(int, input().split(' ')) 5 | answer = A + B 6 | print(answer) 7 | except: 8 | pass 9 | -------------------------------------------------------------------------------- /codechef problems/atm.py: -------------------------------------------------------------------------------- 1 | try: 2 | x = int(input()) 3 | y = float(input()) 4 | 5 | if x%5==0 and x>0 and y>0 and y>x: 6 | print(y-x-0.50) 7 | else: 8 | print(y) 9 | except: 10 | pass -------------------------------------------------------------------------------- /codechef problems/chef_and_equality.cpp: -------------------------------------------------------------------------------- 1 | #include 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 | int n; 11 | cin>>n; 12 | int arr[n]; 13 | mapmp; 14 | for(int i=0;i>arr[i]; 16 | mp[arr[i]]++; 17 | } 18 | int mx=0; 19 | for(int i=0;iB: 6 | print('>') 7 | elif A0: 8 | for i in price: 9 | if p>=i: 10 | s = s +p//i 11 | p = p%i 12 | print(s) 13 | 14 | 15 | except: 16 | pass -------------------------------------------------------------------------------- /codechef problems/cube_in_triangles.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | for i in range(t): 4 | b = int(input()) 5 | b = b-2 6 | b = b//2 7 | x = b*(b+1) 8 | y = x//2 9 | print(y) 10 | 11 | except: 12 | pass -------------------------------------------------------------------------------- /codechef problems/cupcakes.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | for i in range(t): 4 | N = int(input()) 5 | pack = (N//2)+1 6 | print(pack) 7 | 8 | except: 9 | pass -------------------------------------------------------------------------------- /codechef problems/currency.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | 4 | for i in range(tc): 5 | currency = [100,50,10,5,2,1] 6 | amount = int(input()) 7 | count = 0 8 | 9 | for i in currency: 10 | if amount>1: 11 | count = count+(amount//i) 12 | amount = amount%i 13 | print(count) 14 | 15 | except: 16 | pass -------------------------------------------------------------------------------- /codechef problems/dec_inc.py: -------------------------------------------------------------------------------- 1 | try: 2 | N = int(input()) 3 | if N%4==0: 4 | print(N+1) 5 | else: 6 | print(N-1) 7 | 8 | except: 9 | pass -------------------------------------------------------------------------------- /codechef problems/diffsum.py: -------------------------------------------------------------------------------- 1 | try: 2 | n1 = int(input()) 3 | n2 = int(input()) 4 | if n1>n2: 5 | print(n1-n2) 6 | else: 7 | print(n1+n2) 8 | 9 | except: 10 | pass -------------------------------------------------------------------------------- /codechef problems/digit_sum.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | 4 | for i in range(t): 5 | n = int(input()) 6 | a = n 7 | sum = 0 8 | while n!=0: 9 | a = n%10 10 | sum+=0 11 | n//=10 12 | print(sum) 13 | except: 14 | pass -------------------------------------------------------------------------------- /codechef problems/enormous_input_test.py: -------------------------------------------------------------------------------- 1 | try: 2 | n, k = map(int, input().split(' ')) 3 | ans = 0 4 | for i in range(0,n): 5 | c = int(input()) 6 | i+=1 7 | if c%k == 0: 8 | ans += 1 9 | print(ans) 10 | except: 11 | pass -------------------------------------------------------------------------------- /codechef problems/exoenses.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | for i in range(t): 4 | a,b = map(int, input().split()) 5 | if a<1000: 6 | print(a*b) 7 | elif a>1000: 8 | print(a*b - (a*b)*0.1) 9 | 10 | 11 | except: 12 | pass -------------------------------------------------------------------------------- /codechef problems/factorial.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | for i in range(tc): 4 | a = int(input()) 5 | factorial = 1 6 | for j in range(1,a+1): 7 | factorial = factorial*j 8 | print(factorial) 9 | except: 10 | pass -------------------------------------------------------------------------------- /codechef problems/gcd_lcm.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | while t>0: 4 | a,b = map(int, input().split()) 5 | mul = a*b 6 | while(b%a!=0): 7 | r = b%a 8 | b = a 9 | a = r 10 | print(a, mul//a) 11 | 12 | 13 | 14 | except: 15 | pass -------------------------------------------------------------------------------- /codechef problems/helping_chef.py: -------------------------------------------------------------------------------- 1 | try: 2 | T = int(input()) 3 | for i in range(T): 4 | N =int(input()) 5 | if N<10: 6 | print("Thanks for helping Chef!") 7 | else: 8 | print(-1) 9 | except: 10 | pass -------------------------------------------------------------------------------- /codechef problems/id&ship.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | for i in range(tc): 4 | ch = input() 5 | if ch == 'B' or ch == 'b': 6 | print('BattleShip') 7 | elif ch =='C' or ch == 'c': 8 | print('Cruiser') 9 | elif ch == 'D' or ch == 'd': 10 | print('Destroyer') 11 | elif ch == 'F' or ch == 'f': 12 | print('Frigate') 13 | 14 | except: 15 | pass -------------------------------------------------------------------------------- /codechef problems/lead_game.py: -------------------------------------------------------------------------------- 1 | try: 2 | n = int(input()) 3 | p1 = 0 4 | p2 = 0 5 | lead = 0 6 | l = 0 7 | plr = 0 8 | win = 0 9 | for i in range(0,n): 10 | a,b = input().split(' ') 11 | p1+=int(a) 12 | p2+=int(b) 13 | if (p1>p2): 14 | lead = p1 - p2 15 | plr = 1 16 | else: 17 | lead = p2 - p1 18 | plr = 2 19 | if (lead>1): 20 | l=lead 21 | win = plr 22 | print(win,end = " ") 23 | print(l) 24 | except: 25 | pass -------------------------------------------------------------------------------- /codechef problems/lucky_four.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | for i in range(t): 4 | b = int(input()) 5 | x = b 6 | result = x.find('4') 7 | print(result) 8 | except: 9 | pass -------------------------------------------------------------------------------- /codechef problems/mahasena.py: -------------------------------------------------------------------------------- 1 | try: 2 | sol = int(input()) 3 | A = input() 4 | weapons = A.split(" ") 5 | odd = 0 6 | even = 0 7 | for i in weapons: 8 | if int(i)%2 ==0: 9 | even = even + 1 10 | elif int(i)%2 == 1: 11 | odd = odd + 1 12 | 13 | if even > odd: 14 | print("READY FOR BATTLE") 15 | else: 16 | print("NOT READY") 17 | 18 | 19 | except: 20 | pass -------------------------------------------------------------------------------- /codechef problems/palindrome.py: -------------------------------------------------------------------------------- 1 | try: 2 | l = [] 3 | for i in range(int(input())): 4 | c = input() 5 | for i in c: 6 | l.append(i) 7 | if l == l[: : -1]: 8 | print('wins') 9 | else: 10 | print('loses') 11 | l = [] 12 | 13 | except: 14 | pass -------------------------------------------------------------------------------- /codechef problems/ppsum.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | while t>0: 4 | d, n = map(int, input().split()) 5 | for i in range(1,d+1): 6 | n = (n*(n+1))/2 7 | 8 | 9 | print(int(n)) 10 | t = t-1 11 | 12 | except: 13 | pass -------------------------------------------------------------------------------- /codechef problems/primality.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | prime = False 4 | for i in range(tc): 5 | 6 | p = int(input()) 7 | if p > 1: 8 | for i in range(2,p): 9 | if p%i ==0: 10 | prime = True 11 | break 12 | 13 | if prime: 14 | print("no") 15 | else: 16 | print("yes") 17 | 18 | 19 | except: 20 | pass -------------------------------------------------------------------------------- /codechef problems/remainder.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | for i in range(tc): 4 | a, b = map(int, input().split(' ')) 5 | print(a%b) 6 | except: 7 | pass 8 | -------------------------------------------------------------------------------- /codechef problems/reverse.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | for i in range(t): 4 | a = int(input()) 5 | b = str(a) 6 | b_length = len(b) 7 | slice_String = b[::-1] 8 | print(int(slice_String)) 9 | 10 | except: 11 | pass -------------------------------------------------------------------------------- /codechef problems/reverseint.js: -------------------------------------------------------------------------------- 1 | 2 | // --- Directions 3 | // Given an integer, return an integer that is the reverse 4 | // ordering of numbers. 5 | // --- Examples 6 | // reverseInt(15) === 51 7 | // reverseInt(981) === 189 8 | // reverseInt(500) === 5 9 | // reverseInt(-15) === -51 10 | // reverseInt(-90) === -9 11 | 12 | function reverseInt(n) { 13 | const reversed = n 14 | .toString() 15 | .split('') 16 | .reverse() 17 | .join(''); 18 | 19 | return parseInt(reversed) * Math.sign(n); 20 | } 21 | 22 | module.exports = reverseInt; 23 | -------------------------------------------------------------------------------- /codechef problems/second_largets.py: -------------------------------------------------------------------------------- 1 | try: 2 | n=int(input()) 3 | for i in range(1,n+1): 4 | s=[] 5 | a,b,c=map(int,input().split()) 6 | s.append(a) 7 | s.append(b) 8 | s.append(c) 9 | s.sort() 10 | print(s[1]) 11 | 12 | 13 | except: 14 | pass -------------------------------------------------------------------------------- /codechef problems/small_factorial.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | for i in range(tc): 4 | a = int(input()) 5 | factorial = 1 6 | for j in range(1,a+1): 7 | factorial = factorial*j 8 | print(factorial) 9 | except: 10 | pass -------------------------------------------------------------------------------- /codechef problems/square_root.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | for i in range(t): 4 | a = int(input()) 5 | print(int(a**(1/2))) 6 | 7 | except: 8 | pass -------------------------------------------------------------------------------- /codechef problems/sum_1st&last_digit.py: -------------------------------------------------------------------------------- 1 | try: 2 | tc = int(input()) 3 | for i in range(tc): 4 | n = int(input()) 5 | length = len(str(n)) 6 | first = n//(10**(length-1)) 7 | last = n%10 8 | 9 | print(first + last) 10 | 11 | except: 12 | pass -------------------------------------------------------------------------------- /codechef problems/tempCodeRunnerFile.py: -------------------------------------------------------------------------------- 1 | for i in range(int(input())): 2 | c = input() 3 | for i in c: 4 | l.append(i) 5 | if l == l[: : -1]: 6 | print('wins') 7 | else: 8 | print('loses') 9 | l = [] -------------------------------------------------------------------------------- /codechef problems/turbo_sort.py: -------------------------------------------------------------------------------- 1 | try: 2 | t = int(input()) 3 | a = [] 4 | for i in range(t): 5 | b = int(input()) 6 | a.append(b) 7 | 8 | a.sort() 9 | 10 | for j in range(len(a)): 11 | print(a[j]) 12 | except: 13 | pass -------------------------------------------------------------------------------- /codechef problems/valid_triangles.py: -------------------------------------------------------------------------------- 1 | try: 2 | T = int(input()) 3 | for i in range(T): 4 | A, B, C = map(int,input().split()) 5 | if A + B + C == 180: 6 | print("YES") 7 | else: 8 | print("NO") 9 | 10 | except: 11 | pass -------------------------------------------------------------------------------- /contribution guideline . md: -------------------------------------------------------------------------------- 1 | Contributing guidelines, the CONTRIBUTING.md file, or software contribution guidelines, is a text file which project managers include in free and open-source software packages or other open media packages for the purpose of describing how others may contribute user-generated content to the project. 2 | 3 | The file explains how anyone can engage in activities such as formatting code for submission or submitting patches.[1] 4 | 5 | The existence of the file in a package should increase the chance of a project receiving crowdsourced contributions.[2] But in many cases, the received contributions do not follow the instructions in the file.[3] 6 | 7 | Having a contributions file greatly contributes to the success of projects which depend on user contributions.[4] 8 | -------------------------------------------------------------------------------- /cracking image/CSS Only Portrait.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CSS Only Portrait 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | -------------------------------------------------------------------------------- /cracking image/CSS Only Portrait_files/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/CSS Only Portrait_files/image.jpg -------------------------------------------------------------------------------- /cracking image/CSS Only Portrait_files/style.css: -------------------------------------------------------------------------------- 1 | * 2 | { 3 | margin: 0; 4 | padding: 0; 5 | box-sizing: border-box; 6 | } 7 | 8 | .portrait{ 9 | position: absolute; 10 | top: 0; 11 | left: 0; 12 | width: 100%; 13 | height: 100vh; 14 | } 15 | 16 | .portrait img{ 17 | position: absolute; 18 | top: 0; 19 | left: 0; 20 | width: 100%; 21 | height: 100%; 22 | object-fit: cover; 23 | } 24 | 25 | .portrait img.texture{ 26 | mix-blend-mode: multiply; 27 | filter: contrast(1.2); 28 | } -------------------------------------------------------------------------------- /cracking image/CSS Only Portrait_files/texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/CSS Only Portrait_files/texture.jpg -------------------------------------------------------------------------------- /cracking image/drew-hays-Kt8eGw8_S8Y-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/drew-hays-Kt8eGw8_S8Y-unsplash.jpg -------------------------------------------------------------------------------- /cracking image/dynamic-wang-3iixjTc--_k-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/dynamic-wang-3iixjTc--_k-unsplash.jpg -------------------------------------------------------------------------------- /cracking image/georgia-mashford-UzxZBo7nP9E-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/georgia-mashford-UzxZBo7nP9E-unsplash.jpg -------------------------------------------------------------------------------- /cracking image/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CSS Only Portrait 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | 14 | -------------------------------------------------------------------------------- /cracking image/ramin-khatibi-OG8L9s1bYKc-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/ramin-khatibi-OG8L9s1bYKc-unsplash.jpg -------------------------------------------------------------------------------- /cracking image/style.css: -------------------------------------------------------------------------------- 1 | * 2 | { 3 | margin: 0; 4 | padding: 0; 5 | box-sizing: border-box; 6 | } 7 | 8 | .portrait{ 9 | position: absolute; 10 | top: 0; 11 | left: 0; 12 | width: 100%; 13 | height: 100vh; 14 | } 15 | 16 | .portrait img{ 17 | position: absolute; 18 | top: 0; 19 | left: 0; 20 | width: 100%; 21 | height: 100%; 22 | object-fit: cover; 23 | } 24 | 25 | .portrait img.texture{ 26 | mix-blend-mode: multiply; 27 | filter: contrast(1.2); 28 | } -------------------------------------------------------------------------------- /cracking image/texture.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/texture.jpg -------------------------------------------------------------------------------- /cracking image/vincent-burkhead-LhlxYMfnTF0-unsplash.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shivprime94/Data-Structure-Algorithms/ce7127f6dd70147419af7b780540c0218a7c5a79/cracking image/vincent-burkhead-LhlxYMfnTF0-unsplash.jpg -------------------------------------------------------------------------------- /initial.py: -------------------------------------------------------------------------------- 1 | print("hello world") -------------------------------------------------------------------------------- /leetcode hard/EditDistance.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | int min(int x, int y, int z){return x < y ? (x < z ? x : z) : (y < z ? y : z);} 3 | 4 | public: 5 | int minDistance(string word1, string word2) { 6 | int m=word1.length(); 7 | int n=word2.length(); 8 | int dp[m+1][n+1]; 9 | 10 | for(int i=0;i<=m;i++){ 11 | for(int j=0;j<=n;j++){ 12 | if(i==0){ 13 | dp[i][j]=j; 14 | } 15 | else if(j==0){ 16 | dp[i][j]=i; 17 | } 18 | else if(word1[i-1]==word2[j-1]){ 19 | dp[i][j]=dp[i-1][j-1]; 20 | } 21 | else{ 22 | dp[i][j]=1+min(dp[i-1][j],dp[i][j-1],dp[i-1][j-1]); 23 | } 24 | } 25 | } 26 | return dp[m][n]; 27 | } 28 | }; 29 | 30 | -------------------------------------------------------------------------------- /leetcode hard/FancySequence.cpp: -------------------------------------------------------------------------------- 1 | class Fancy { 2 | public: 3 | #define MOD 1000000007 4 | 5 | vector> op; 6 | vector> table; 7 | 8 | void append(int val) { 9 | table.push_back({op.size(), val}); 10 | } 11 | 12 | void addAll(int inc) { 13 | op.push_back({0, inc}); 14 | } 15 | 16 | void multAll(int m) { 17 | op.push_back({1, m}); 18 | } 19 | 20 | int getIndex(int idx) { 21 | if(idx >= table.size()) 22 | return -1; 23 | 24 | auto &[id , num] = table[idx]; 25 | for(;id != op.size(); id++) 26 | if(op[id].first) 27 | num = (long(num) * op[id].second) % MOD; 28 | else 29 | num = (long(num) + op[id].second) % MOD; 30 | 31 | return num; 32 | } 33 | }; -------------------------------------------------------------------------------- /leetcode hard/minimum_window_substring.cpp: -------------------------------------------------------------------------------- 1 | class Solution { 2 | public: 3 | string minWindow(string s, string t) { 4 | unordered_map m; 5 | for(char c : t) m[c]++; 6 | 7 | int i = 0, d = INT_MAX, cnt = m.size(); 8 | string ans; 9 | for(int j=0; j 0) cnt++; 19 | } 20 | i++; 21 | } 22 | } 23 | return ans; 24 | } 25 | }; -------------------------------------------------------------------------------- /leetcodeproblems/medium/kth largest element in an array.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Given an integer array nums and an integer k, return the kth largest element in the array. 3 | Note that it is the kth largest element in the sorted order, not the kth distinct element. 4 | You must solve it in O(n) time complexity. 5 | 6 | Example 1: 7 | Input: nums = [3,2,1,5,6,4], k = 2 8 | Output: 5 9 | */ 10 | 11 | #include 12 | #include 13 | class Solution { 14 | public: 15 | int findKthLargest(vector& nums, int k) 16 | { 17 | priority_queue pq; 18 | for(int i=0;i 4 | using namespace std; 5 | 6 | int maxSum(int arr[], int n) 7 | { 8 | // Sort the array 9 | sort(arr, arr + n); 10 | 11 | // Finding the sum of arr[i]*i 12 | int sum = 0; 13 | for (int i = 0; i < n; i++) 14 | sum += (arr[i] * i); 15 | 16 | return sum; 17 | } 18 | 19 | // Driven Program 20 | int main() 21 | { 22 | int arr[] = { 3, 5, 6, 1 }; 23 | int n = sizeof(arr) / sizeof(arr[0]); 24 | 25 | cout << maxSum(arr, n) << endl; 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /primeprint2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | int prime(int n){ 6 | int count =0; 7 | for(int i=1;i<=sqrt(n);i++){ 8 | if(n%i==0){ 9 | count++; 10 | } 11 | } 12 | if(count==1){ 13 | return 1; 14 | } 15 | else{ 16 | return 0; 17 | } 18 | } 19 | int main(){ 20 | int n; 21 | cin>>n; 22 | int flag=0; 23 | for(int i=2;i int: 2 | bin_string = str(bin_string).strip() 3 | if not bin_string: 4 | raise ValueError("Empty string was passed to the function") 5 | is_negative = bin_string[0] == "-" 6 | if is_negative: 7 | bin_string = bin_string[1:] 8 | if not all(char in "01" for char in bin_string): 9 | raise ValueError("Non-binary value was passed to the function") 10 | decimal_number = 0 11 | for char in bin_string: 12 | decimal_number = 2 * decimal_number + int(char) 13 | return -decimal_number if is_negative else decimal_number 14 | 15 | 16 | if __name__ == "__main__": 17 | from doctest import testmod 18 | 19 | testmod() -------------------------------------------------------------------------------- /python/fibonacci_sequence.py: -------------------------------------------------------------------------------- 1 | # fibonacci series 2 | # 0, 1, 1, 2, 3, 5, 8, ... 3 | 4 | n = int(input("No. of terms? ")) 5 | 6 | n_1, n_2 = 0, 1 7 | counter = 0 8 | 9 | if n <= 0: 10 | print("Please input a positive integer value") 11 | elif n == 1: 12 | print("Fibonacci series ", n, ":") 13 | print(n_1) 14 | else: 15 | print("Fibonacci sequence:") 16 | while counter < n: 17 | print(n_1) 18 | n_f = n_1 + n_2 19 | n_1 = n_2 20 | n_2 = n_f 21 | counter += 1 22 | -------------------------------------------------------------------------------- /python/open_dir.py: -------------------------------------------------------------------------------- 1 | import os 2 | print(os.listdir()) -------------------------------------------------------------------------------- /python/random-resturant-generator.py: -------------------------------------------------------------------------------- 1 | import random 2 | print("Are you always having trouble on deciding where to go eat?") 3 | print("let me help you!") 4 | num=random.randint(1, 3) 5 | if num=1 6 | print("go to chiptle!') 7 | else if num=2 8 | print("go to McDonald's") 9 | else 10 | print("go to MOD Pizza!") 11 | -------------------------------------------------------------------------------- /python/selenium_searching_script.py: -------------------------------------------------------------------------------- 1 | import time 2 | 3 | from selenium import webdriver 4 | from selenium.webdriver.common.keys import Keys 5 | 6 | PROXY = '18.220.20.81:8080' 7 | 8 | chrome_options = webdriver.ChromeOptions() 9 | chrome = webdriver.Chrome(executable_path=r"C:\Users\dhane\chromedriver.exe", chrome_options=chrome_options) 10 | chrome.get("https://google.com") 11 | time.sleep(2) 12 | 13 | search_bar = chrome.find_element_by_xpath('/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input') 14 | search_bar.click() 15 | search_bar.send_keys("Python is super cool.") 16 | search_bar.send_keys(Keys.ENTER) 17 | -------------------------------------------------------------------------------- /python/transpose of a matrix.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | n,m = input().split() 4 | arr = input().split() 5 | 6 | arr1 = numpy.array(arr) 7 | arr1.reshape(arr,(int(n),int(m))) 8 | 9 | print(arr1) -------------------------------------------------------------------------------- /sumoftwonumber.cpp: -------------------------------------------------------------------------------- 1 | #inlcude 2 | using namespace std; 3 | int main(){ 4 | int a,b; cin>>a>>b; 5 | cout< 2 | using namespace std; 3 | typedef long long ll; 4 | 5 | ll z[2000005]; 6 | 7 | int main() { 8 | string s; 9 | cin>>s; 10 | ll n=s.size(); 11 | 12 | for (ll i = 1, l = 0, r = 0; i < n; ++i) { 13 | if (i <= r) 14 | z[i] = min (r - i + 1, z[i - l]); 15 | while (i + z[i] < n && s[z[i]] == s[i + z[i]]) 16 | ++z[i]; 17 | if (i + z[i] - 1 > r) 18 | l = i, r = i + z[i] - 1; 19 | } 20 | 21 | for(ll i=1;i