Python Interview Problems For Practice Save

120+ Common code and interview problems solved in Python **(it's GROWING...)** Give a Star 🌟If it helps you. Please go through the before starting.

Project README

Python-Interview-Problems-for-Practice (now supported with Code Style)

star this repo fork this repo Code style: black


Problem Link
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
Convert the string "123" into 123, without using the built-api int()
Given an array , find if the number exists, develop a recursive implementation of the binary search. If the element is not found it returns -1
Bresenham Line Algorithm (BLA) is one of the earliest algorithms developed in computer graphics. It is used for drawing lines
Find the no. of nodes in a BST that lies in a given range
Bubble Sort
Find the angle made by the hour hand and the minute hand at any given time. Assume it is an analog clock
Two strings of sizes m and n are given, we have to find how many characters need to be removed from both the string so that they become anagrams of each other
Find the numbers which are semiprimes, within a given range. A semiprime is a product of two prime numbers, not necessarily distinct. Squares of prime numbers are also semiprimes.
Given a graph, there are two methods to perform traversal on it 1. Depth First Search (DFS) 2. Breadth First Search (BFS)
The diameter of a tree (sometimes called the width) is the number of nodes on the longest path between two end nodes(leftmost leaf node and rightmost leaf node).
Estimate pi using random distribution
Write an efficient program for printing k largest elements in an array. Elements in array can be in any order.
Given a linked list, this method will return m'th element to the last 2->3->4->8->5; m=2 will return 8 since 8 is second to last
Given an array of numbers, find all the pairs of numbers which sum upto k
Given an array of numbers, find all the pairs of numbers whose product is k
Given an array of integers, write a function that returns true if there is a triplet (a, b, c) that satisfies a^2 + b^2 = c^2.
Given a binary tree, find the second largest node in it
Write a function that computes the list of the first 100 Fibonacci numbers
Given an input string, it gives the first non repeating character in it
Given an input string, find the first recurring character in it.
Given a string, find the first non-repeating character in it. For example, if the input string is “GeeksforGeeks”, then output should be ‘f’ and if input string is “GeeksQuiz”, then output should be ‘G’.
Write a function that given a list of non negative integers, arranges them such that they form the largest possible number. For example, given [50, 2, 1, 9], the largest formed number is 95021
Tree Data Structure in Python
Given the arrival and departure times of all trains that reach a railway station, the task is to find the minimum number of platforms required for the railway station so that no train waits.

We are given two arrays that represent the arrival and departure times of trains that stop.
Print duplicate characters in a string
Check if a given array has zero sum sub array
Given a string, check if it only contains digits
Given two lat, long coordinates , calculate Haversine distance between them
Heap Data Structure
Print numbers 1 to 100 without using any numbers or integers
Write a program to convert interger to Roman Representation
Given two sorted array of sizes m and n in which all elements are distinct. Find the common elements between them
Check if a matrix is symmetric or not
Check if two strings are anagrams of each other
Check if two strings are anagrams of each other
Write a program to check if a number is a palindrome or not
Given a string, return True if it is a numeric data type, False otherwise
N soldiers are standing in a circle and first person has sword and he kills the 2nd person and gives the sword to the third person and so on till 99th person kills the 100th person gives the sword back to the first person, this goes on till only one person survives. Print the survivor.
The effective time complexity of this improved version is O(logN). For the problem statement, refer
The effective time complexity of this improved version is O(1). For the problem statement, refer
Implement the Karatsuba algorithm
Implement Level Order traversal for a binary tree
Linked List Data Structure
Detect if a linked list has a loop
Find the Lowest Common ancestor between two nodes in a binary search tree. Let T be a rooted tree. The lowest common ancestor between two nodes n1 and n2 is defined as the lowest node in T that has both n1 and n2 as descendants (where we allow a node to be a descendant of itself).

The LCA of n1 and n2 in T is the shared ancestor of n1 and n2 that is located farthest from the root.
A majority element in an array A[] of size n is an element that appears more than n/2 times. Find the majority element in the given array.
Find the max number in an array without using built-in functions
Given a list of positive and negative numbers, find the maximum subarray sum. Constraint: Solve it in O(n)
Implementation of Merge Sort
Find the minimum and maximum numbers in an array in a single loop
Given an array of integers we need to move all the zeroes to the end and maintain the order of rest of the elements. Needless to say it should be an in-place solution
Print the nodes of a binary tree which do not have a sibling
Let all odd numbers come before even numbers, and sort the odd numbers in ascending order and even numbers in descending order. For example, the string '1982376455' becomes '1355798642'
Compute and print the pascal traingle, given the no. of levels
using factorial, reduced the time complexity of program from O(2^N) to O(N)
Print the permutations of a string
Print the permutatations of a string (Simplified)
Preorder Traversal of a Binary Search Tree in Iterative fashion
Implementation of a priority Queue
Process the string "k:1 k1:2
Given an array arr[] of n integers, construct a Product Array prod[] (of same size) such that prod[i] is equal to the product of all the elements of arr[] except arr[i].
Implementation of a Queue Data Structure
Implementation of Quick Sort
Write an efficient function that deletes characters from an ASCII string where any character existing in remove must be deleted from str. For example, given a str of "Battle of the Vowels: Hawaii vs. Grozny" and a remove of "aeiou", the function should transform str to “Bttl f th Vwls: Hw vs. Grzny”.
Remove duplicate characters from string
Remove duplicates using a dictionary
Remove duplicates using extra space
Reverse the string in place
Reverse the string using recursion
Given a sentence, reverse each word but don't reverse the sentence
Given a matrix, rotate it by 180 degree
Find Median from Data Stream of integers
Given a sorted array in which all elements appear twice (one after one) and one element appears only once. Find that element Constraints: in O(log n) complexity.
A simple implementation of Selection Sort
A simple implementation of Stack Data Structure
The span Si of the stock’s price on a given day i is defined as the maximum number of consecutive days just before the given day, for which the price of the stock on the current day is less than or equal to its price on the given day.

Problem: We have a series of n daily price quotes for a stock and we need to calculate span of stock’s price for all n days
Write a program to sum a given array using recursion
You are getting two streams of data with dates as key, merge the two streams and return average of the values if there is a common date else just update the value as received in the stream, refer example in the code
Given two sorted array of sizes m and n in which all elements are distinct. Find the union between them Constraints: in O(m+n) complexity.
Username validation program
Given an array of integers(+ve,-ve and 0) find the sign of the product of all the given values.

Problems available: Solved -- 63 ; Newly Added -- 57

1. Code Style is added

2. 57 new problems are added in Solutions to be uploaded soon.

alt text 40+ Common code and interview problems solved in Python (it's growing...)

The core idea is not to utilize built-in functions or library and giving it a more logic-based approach, so that it can be language-friendly and not end up being another repository of "Python Tips and Tricks" .

How good is the code ?

  • It is well tested
  • Consistent formatting (using Black)
  • It can compile in its current state (and there are relatively no issues)

How much support is available?

  • FAQs (coming soon)
  • Documentation (coming soon)


Feel free to submit issues and enhancement requests.


Please refer to each project's style guidelines and guidelines for submitting patches and additions. In general, we follow the "fork-and-pull" Git workflow.

  1. Fork the repo on GitHub
  2. Clone the project to your own machine
  3. Commit changes to your own branch
  4. Push your work back up to your fork
  5. Submit a Pull request so that we can review your changes

NOTE: Be sure to merge the latest from "upstream" before making a pull request!


MIT License

Open Source Agenda is not affiliated with "Python Interview Problems For Practice" Project. README Source: devAmoghS/Python-Interview-Problems-for-Practice

Open Source Agenda Badge

Open Source Agenda Rating