8000 GitHub - ttran2407/algorithms_and_data_structures: Algorithm & Data Structure Problems using C++
[go: up one dir, main page]

Skip to content

ttran2407/algorithms_and_data_structures

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Practice Problems w/ Solutions

From the book, "Cracking the Coding Interview"
Problem Solution
Problem 1-1 : Edition 6: Write an algorithm to determine whether a string has unique characters or not. Can we do it without using additional data structures? 1-1-hasUniqueChars.cpp
Problem 1-2 : Edition 5: Reverse a string when you are a pass a null terminated C string. 1-2-edi5-reverseString.cpp
Problem 1-2 : Edition 6: Given two strings, determine if one is permutation of other. 1-2-perm-strings.cpp
Problem 1-3 : Edition 5: Write an algorithm to remove duplicate chars from a string. 1-3-edi5-removeDuplicates.cpp
Problem 1-3 : Edition 6: URLify: Replace all the spaces in a string with '%20'. Preferebly Inplace 1-3-URLify.cpp
Problem 1-4 : Edition 6: Given a string, write a function to check if it is a permutation of a pallindrome. 1-4-pallindrome-permutations.cpp
Problem 1-5 : Edition 6: There are three possible edits that can be performed on a string - Insert a char, Delete a char, Replace a char. Given two strings, determine if they are one or 0 edit away. 1-5-one-edit-away.cpp
Problem 1-6: Implement a method to perform basic string compression. Example string aabcccccaaa should be compressed to a2b1c5a3, however if compressed string is bigger than original string, return original string 1-6-string-compression.cpp
Problem 1-7: Rotate the matrix clockwise( & anticlockwise) by 90 degrees 1-7-matrix-rotation.cpp
Problem 1-8: Write an algorithm such that if an element of MxN matrix is 0, its entire row and column is set to 0. 1-8-zero-matrix.cpp
Problem 1-9: Given two strings s1 and s2, determine s2 is rotation of s1 using only one call to a function which checks whether one string is rotation of another. 1-9-string-rotation.cpp
Problem 2-1: Remove duplicates from an unsorted linked list. What if no temporary buffer is allowed. 2-1-remove-dups.cpp
Problem 2-2: Determine kth node from the last of a singly linked list. (Iterative and Recursive Approaches) 2-2-kthToLast.cpp
Problem 2-3: Implement an algorithm to delete a node in the middle of a singly linked list 2-3-delete-middle-node.cpp
Problem 2-4: Partition a linked list around a value x, all the nodes smaller than x come before all the nodes greater than equal to x 2-4-partition.cpp
Problem 2-5: You have two numberse represented by a linked list where each node contains a single digit. The digits are stored in reversed order, such that 1's digits are at the head of the list. Write a function that adds the two numbers and returns the sum as a linked list.Example:
  • Input: ( 7 --> 1 --> 6 ) + ( 5 --> 9 --> 2 ) that is 617 + 295
  • Output: ( 2 --> 1 --> 9 ) i.e. 912.
  • FOLLOW UP : Suppose the lists are stored in forward order, Repeat the above problem.
  • Input: ( 6 --> 1 --> 7 ) + ( 2 --> 9 --> 5 ) i.e. 617 + 295
  • Output: ( 9 --> 1 --> 2 ) i.e. 912.
  • Implement it recursively and iteratively.
2-5-add-lists.cpp
Problem 2-6: Determine if linked list is palindrome( 2 iterative and one recursive approach 2-6-palindrome.cpp
Problem 2-7: Determine if two singly linked list intersect, if yes, return the intersecting node. The intersection is defined based on reference not on values 2-7-intersection.cpp
Problem 2-8: Detect if the linked list have a loop, Find the start node of the loop and remove the loop 2-8-loop-detection.cpp

About

Algorithm & Data Structure Problems using C++

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 96.6%
  • Python 2.3%
  • Other 1.1%
0