Code Monkey home page Code Monkey logo

ctci-python-solutions's Introduction

Cracking the Coding Interview in Python - Solutions with Explanations

Detailed explanations to the coding interview questions in CTCI. The solutions are written in Python 3.

If you find this useful, a Github star would be much appreciated!! ⭐ ⭐ ⭐

Arrays and Strings

Problem Number Problem Name Status
1.1 Is Unique Read Solution ✅
1.2 Check Permutation Read Solution ✅
1.3 URLify Read Solution ✅
1.4 Palindrome Permutation Read Solution ✅
1.5 One Away Read Solution ✅
1.6 String Compression Read Solution ✅
1.7 Rotate Matrix Read Solution ✅
1.8 Zero Matrix Read Solution ✅
1.9 String Rotation Read Solution ✅

Linked Lists

Problem Number Problem Name Status
2.1 Remove Dups Read Solution ✅
2.2 Return Kth to Last Read Solution ✅
2.3 Delete Middle Node Read Solution ✅
2.4 Partition Read Solution ✅
2.5 Sum List Read Solution ✅
2.6 Palindrome Read Solution ✅
2.7 Intersection Read Solution ✅
2.8 Loop Detection Read Solution ✅

Stacks and Queues

Problem Number Problem Name Status
3.1 Three In One Read Solution ✅
3.2 Stack Min Read Solution ✅
3.3 Stack of Plates Read Solution ✅
3.4 Queue via Stacks Read Solution ✅
3.5 Sort Stack
3.6 Animal Shelter

Trees and Graphs

Problem Number Problem Name Status
4.1 Route Between Nodes
4.2 Minimal Tree
4.3 List of Depths
4.4 Check Balanced
4.5 Validate BST
4.6 Successor
4.7 Build Order
4.8 First Common Ancestor
4.9 BST Sequence
4.10 Check Subtree
4.11 Random Node
4.12 Paths with Sum

Bit Manipulation

Problem Number Problem Name Status
5.1 Insertion
5.2 Binary to String
5.3 Flip Bit to Win
5.4 Next Number
5.5 Debugger
5.6 Conversion
5.7 Pairwise Swap
5.8 Draw Line

Object Oriented Design

Problem Number Problem Name Status
7.1 Deck of Cards
7.2 Call Center
7.3 Jukebox
7.4 Parking Lot
7.5 Online Book Reader
7.6 Jigsaw
7.7 Chat Server
7.8 Othello
7.9 Circular Array

Recursion and Dynamic Programming

Problem Number Problem Name Status
8.1 Triple Step
8.2 Robot in a Grid
8.3 Magic Index
8.4 Power Set
8.5 Recursive Multiply
8.6 Towers of Hanoi
8.7 Permutation without Dups
8.8 Permutation with Dups
8.9 Parens
8.10 Paint Fill
8.11 Coins
8.12 Eight Queens
8.13 Stack of Boxes
8.14 Boolean Evaluation

Sorting and Searching

Problem Number Problem Name Status
10.1 Sorted Merge
10.2 Group Anagram
10.3 Search in Rotated Array
10.4 Sorted Search, No Size
10.5 Sparse Search
10.6 Sort Big File
10.7 Missing Int
10.8 Find Duplicates
10.9 Sorted Matrix Search
10.10 Rank from Stream
10.11 Peaks and Valleys

Moderate

Problem Number Problem Name Status
16.1 Number Swapper Read Solution ✅
16.2 Word Frequencies Read Solution ✅
16.3 Intersection
16.4 Tic Tac Win
16.5 Factorial Zeros
16.6 Smallest Difference
16.7 Number Max
16.8 English Int
16.9 Operations
16.10 Living People
16.11 Diving Board
16.12 XML Encoding
16.13 Bisect Squares
16.14 Best Line
16.15 Master Mind
16.16 Sub Sort
16.17 Contiguous Sequence
16.18 Pattern Matching
16.19 Pond Sizes
16.20 T9
16.21 Sum Swap
16.22 Langton's Ant
16.23 Rand7 from Rand5
16.24 Pairs with Sum
16.25 LRU Cache
16.26 Calculator

Hard

Problem Number Problem Name Status
17.1 Add Without Plus
17.2 Shuffle
17.3 Random Set
17.4 Missing Number
17.5 Letters and Numbers
17.6 Count of 2s
17.7 Baby Names
17.8 Circus Tower
17.9 Kth Multiple
17.10 Majority Element
17.11 Word Distance
17.12 BiNode
17.13 Re-Space
17.14 Smallest K
17.15 Longest Word
17.16 The Masseuse
17.17 Multi Search
17.18 Shortest Supersequence
17.19 Missing Two
17.20 Continuous Median
17.21 Volume of Histogram
17.22 Word Transformer
17.23 Max Black Square
17.24 Max Submatrix
17.25 Word Rectangle
17.26 Sparse Similarity

If you find this useful, a Github star would be much appreciated!! ⭐ ⭐ ⭐

Contributing

Pull requests are welcome. For major changes, please open an issue to discuss what you want to change.

Contributors

Huge thanks to our contributors!

ctci-python-solutions's People

Contributors

arpankg avatar farhanjune avatar fediaz3 avatar gan3i avatar konantian avatar rohit-lunavara avatar subash774 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ctci-python-solutions's Issues

Solution 1.8 - Incorrect output matrix

The output matrix should be:
[
[1, 0, 3, 0],
[0, 0, 0, 0],
[6, 0, 1, 0],
[0, 0, 0, 0]
]
instead of
[
[1,0,3,4],
[5,0,7,8],
[6,0,1,2],
[0,0,0,0]
]

row 2 (matrix[1]) becomes 0 because matrix[1][1] (item next to 5 in second row) is 0 and the last column becomes 0 because the last item in the column is 0.

Solution links

Great work with the solutions! I've been trying to access the solution links but I keep getting 404 error.

Generating webpages from .mdx

Hey @arpan74,
I was going through CTCI chapter 16 - Moderate so thought I might as well contribute as I am doing them anyway.

Question:
Are the links dynamically generated or are they hardcoded? I am referring to the header and readme status links to "Read solution".
In other words, if I was to push a file explaining question 16.1, how would you want me to format the header? Leave the link as blank so you can update them later or are these mdx file fed into a system somewhere that generates dynamic webpages as the mdx files are pushed to this repo?

Solution 1.4 - Incorrect dictionary iterator

Line 43 should use the items() method over the dictionary to return (key, value) pairs.

for (key, value) in counts.items():

Or, use the values() method over the dictionary since we are only checking values.

for value in counts.values():

Solution 1.4

Hello! This is my first time using GitHub, so I apologize if this is comment is old news. I wanted to see if this particular solution for question 1.4 might be considered as another option. Thank you for creating this repo! I've been enjoying it.

You are given a string. Write a function that checks if the letters in the string can be rearranged to form a palindrome (or if the input is already a palindrome). You can ignore spaces in the string.

def palindrome(s):
  # Remove spaces
  s = s.replace(" ","")
  # Check if s is == the reversed s
  return s == s[::-1]`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.