• Stars
    star
    971
  • Rank 47,138 (Top 1.0 %)
  • Language
    Jupyter Notebook
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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

star this repo fork this repo Code style: black

Updates

Problem Link
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. adjacentElementProduct.py
Convert the string "123" into 123, without using the built-api int() atoi.py
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 binary_search_recursive.py
Bresenham Line Algorithm (BLA) is one of the earliest algorithms developed in computer graphics. It is used for drawing lines bresenham_line_algorithm.py
Find the no. of nodes in a BST that lies in a given range bst_nodes_in_range.py
Bubble Sort bubbleSort.py
Find the angle made by the hour hand and the minute hand at any given time. Assume it is an analog clock calculateClockAngle.py
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 check_anagrams.py
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. check_semiprime.py
Given a graph, there are two methods to perform traversal on it 1. Depth First Search (DFS) 2. Breadth First Search (BFS) dfs_bfs.py
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). diameterOfTree.py
Estimate pi using random distribution estimate_pi.py
Write an efficient program for printing k largest elements in an array. Elements in array can be in any order. find_k_largest.py
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 find_m_to_last_llist.py
Given an array of numbers, find all the pairs of numbers which sum upto k find_pairs_sum_k.py
Given an array of numbers, find all the pairs of numbers whose product is k find_products_pair_k.py
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. find_pythagoras_triplet.py
Given a binary tree, find the second largest node in it find_second_largest_in_binary_tree.py
Write a function that computes the list of the first 100 Fibonacci numbers first_n_fibo.py
Given an input string, it gives the first non repeating character in it first_non_repeating.py
Given an input string, find the first recurring character in it. first_recurring_character.py
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’. first_unique_letter.py
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 gen_largest_num_frm_list.py
Tree Data Structure in Python general_tree_structure.py
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.
getMinPlatforms.py
Print duplicate characters in a string get_dup_chars.py
Check if a given array has zero sum sub array hasZeroSumSubArray.py
Given a string, check if it only contains digits has_only_digits.py
Given two lat, long coordinates , calculate Haversine distance between them haversine.py
Heap Data Structure heap_structure.py
Print numbers 1 to 100 without using any numbers or integers hundred_without_int.py
Write a program to convert interger to Roman Representation interger_to_roman_num.py
Given two sorted array of sizes m and n in which all elements are distinct. Find the common elements between them intersection_arrays.py
Check if a matrix is symmetric or not isMatrixSymmetric.py
Check if two strings are anagrams of each other is_anagram.py
Check if two strings are anagrams of each other is_anagram_using_collections.py
Write a program to check if a number is a palindrome or not is_num_palindrome.py
Given a string, return True if it is a numeric data type, False otherwise is_numeric.py
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. josephus.py
The effective time complexity of this improved version is O(logN). For the problem statement, refer josephus.py josephus_improved.py
The effective time complexity of this improved version is O(1). For the problem statement, refer josephus.py josephus_improved_v3.py
Implement the Karatsuba algorithm karatsuba.py
Implement Level Order traversal for a binary tree level_order_tree.py
Linked List Data Structure linked_list_data_structure.py
Detect if a linked list has a loop loop_in_linkedlist.py
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.
lowest_common_ancestor.py
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. majority_element.py
Find the max number in an array without using built-in functions max_in_array.py
Given a list of positive and negative numbers, find the maximum subarray sum. Constraint: Solve it in O(n) maximum_subarray_sum.py
Implementation of Merge Sort merge_sort.py
Find the minimum and maximum numbers in an array in a single loop min_max_array_oneLoop.py
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 move_zeros_to_end.py
Print the nodes of a binary tree which do not have a sibling no_sibling_tree.py
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' oddAscEvenDesc.py
Compute and print the pascal traingle, given the no. of levels pascal_triangle.py
using factorial, reduced the time complexity of program from O(2^N) to O(N) pascals_triangle_improved.py
Print the permutations of a string permutations.py
Print the permutatations of a string (Simplified) permute_strings.py
Preorder Traversal of a Binary Search Tree in Iterative fashion preorder_iterative_bst.py
Implementation of a priority Queue priority_queue_simple.py
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]. product_puzzle.py
Implementation of a Queue Data Structure queue_data_structure.py
Implementation of Quick Sort quick_sort.py
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_chars.py
Remove duplicate characters from string remove_dup_chars.py
Remove duplicates using a dictionary remove_duplicates.py
Remove duplicates using extra space remove_duplicates_v2.py
Reverse the string in place reverse_in_place.py
Reverse the string using recursion reverse_str_recursive.py
Given a sentence, reverse each word but don't reverse the sentence reverse_words.py
Given a matrix, rotate it by 180 degree rotateMatrix180Deg.py
Find Median from Data Stream of integers running_median_integers.py
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. search_unique.py
A simple implementation of Selection Sort selection_sort.py
A simple implementation of Stack Data Structure stack_data_structure.py
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
stock_span.py
Write a program to sum a given array using recursion sum_array_recursion.py
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 timeseries.py
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. union_arrays.py
Username validation program username_validation.py
Given an array of integers(+ve,-ve and 0) find the sign of the product of all the given values. signOfProduct.py

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

1. Code Style is added

2. 57 new problems are added in Interview_Questions.md. 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)

Issues

Feel free to submit issues and enhancement requests.

Contributing

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!

LICENSE

MIT License

More Repositories

1

Machine-Learning-with-Python

Small scale machine learning projects to understand the core concepts . Give a Star 🌟If it helps you. BONUS: Interview Bank coming up..!
Python
1,176
star
2

Keras-Style-Transfer

An implementation of "A Neural Algorithm of Artistic Style" in Keras
Python
36
star
3

deep-learning-with-python

Examples and Exercises from Deep Learning with Python - Francis Chollet
Python
6
star
4

machine-learning-for-hackers

Exercises and solutions for Machine Learning for Hackers by Drew Conway & John Myles White
R
6
star
5

covid19-india-impact-dashboard

Website: http://covid19dashboard.pythonanywhere.com/
Python
6
star
6

Telemarketing-Prediction-for-Banking

This is an independent data science notebook where we want to predict and improve whether a customer will buy a term loan or not
Jupyter Notebook
5
star
7

ML-Study-Plan

4
star
8

intermediate-python

Some intermediate python concepts useful for revision
Python
3
star
9

lstm-text-generation

A generative model for text, character-by-character using LSTM recurrent neural networks in Python with Keras. Later extending to make Predictive Keyboard.
Python
3
star
10

BounceGame

Bounce Game developed with HTML and Javascript
2
star
11

Algorithms-Princeton-University

Exercises for Algorithms Course by Princeton University
Python
2
star
12

Data-Structures-Programs

Data Structure Programs in C++, will be refactoring and adding comments soon.
C++
2
star
13

pos-tagger-nltk-scikit-learn

Part-Of-Speech Tagger using custom trained models, implemented with Scikit-Learn and NLTK
Python
2
star
14

news_classifier-scikitlearn

Multinomial Naive Bayes Classifier for newsgroup20 dataset
Python
2
star
15

An-Introduction-To-Machine-Intelligence

Repository containing Jupyter notebooks for the course: An Introduction to Machine Intelligence for Architects and other Nonengineers ETH Zurich, Chair for CAAD, Autumn semester 2019
2
star
16

books-to-finish

These are the books I wish to finish by 2019
2
star
17

devAmoghS.github.io

Github Pages
JavaScript
2
star
18

Hands-On-Machine-Learning-Notebooks

Notebooks for the chapters in "Hands-On Machine Learning with Scikit-Learn and TensorFlow [O'Reily]"
Jupyter Notebook
2
star
19

Spelling-Corrector-Python

Spelling Corrector made with Python, courtesy of Peter Norvig's Essay
Python
2
star
20

inverted-index-nlp

The purpose of an inverted index is to allow fast full text searches, at a cost of increased processing when a document is added to the database. The inverted file may be the database file itself, rather than its index.
Python
2
star
21

Fake-News-Detection-Python

A deep net that lets you detect if a news article is fake or not
Python
2
star
22

Research-papers-

1
star
23

Spark-Intro-to-ML

This repository contains some of my intial work with Spark-Scala and Machine Learning. TODO: Extend it in the future.
1
star
24

The-Data-Science-Manual

Exercise solutions for The Data Science Design Manual - Steven Skiena
1
star
25

ml-interview-prep

This is a repository to collate random questions asked in an ML interview
1
star
26

BookmarkAppDjango

A simple bookmark application made with intention to learn Django
Python
1
star
27

python-interview-practice

Python
1
star
28

ISLR-Lab

This repository contains the program from Introduction to Statistical Learning with R
R
1
star
29

songs-from-youtube

A repository of songs accidently and boy are they amazing !
1
star
30

Python-Programs

A repository of all the solutions to all tutorial questions from SRM University Course Code: 15IT322E
Python
1
star
31

Chrome-Plugins

Plugins made for Google Chrome
1
star
32

UC-Berkeley-CS61A

Exercises for the lectures from Structure and Interpretation of Programs
Python
1
star
33

Steganography-Application

Steganography Application made as a part of college project. Will be adding a demo soon
1
star
34

andrew-ng-machine-learning

This repository contains the program from Coursera - Machine Learning (Andrew Ng)
MATLAB
1
star
35

tensorflow_tutorial

Python
1
star
36

File-Processing-Microservice

A file processing micro-service written with Flask, RethinkDB and VueJS
Python
1
star
37

CRUD-using-ROR

A basic CRUD interface using React on Rails, can be extended as a template. Feel free to raise an issue if you can make it better
Ruby
1
star