Skip to content

AswathSundaram/Python-Problem-Solving

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python-Problem-Solving
Arrays:
Q1: New Year Chaos
It is New Year's Day and people are in line for the Wonderland rollercoaster ride. Each person wears a sticker indicating their initial position in the queue from 1 to n. Any person can bribe the person directly in front of them to swap positions, but they still wear their original sticker. One person can bribe at most two others. Determine the minimum number of bribes that took place to get to a given queue order. Print the number of bribes, or, if anyone has bribed more than two people, print Too chaotic.

Solution

Q2:Array Manipulation
Starting with a 1-indexed array of zeros and a list of operations, for each operation add a value to each the array element between two given indices, inclusive. Once all operations have been performed, return the maximum value in the array.

Solution

Dictionaries and Hashmaps:
Q3:Counting Triplets
You are given an array and you need to find number of tripets of indices such that the elements at those indices are in geometric progression for a given common ratio and i< j <k

Solution

Q4:Frequency Queries
ou are given queries. Each query is of the form two integers described below:

  • 1 x : Insert x in your data structure.
  • 2 y : Delete one occurence of y from your data structure, if present.
  • 3 z : Check if any integer is present whose frequency is exactly z. If yes, print 1 else 0.

The queries are given in the form of a 2-D array queries of size where queries[i][0] contains the operation, and queries[i][1 contains the data element.

Solution

Sorting:
Q5:Merge Sort:Counting Inversions
In an array, arr, the elements at indices i and j (where i<j) form an inversion if arr[i]>arr[j]. In other words, inverted elements arr[i] and arr[j] are considered to be "out of order". To correct an inversion, we can swap adjacent elements.

Solution

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages