├── .gitignore
├── C
├── Algorithms
│ ├── quicksort.c
│ └── quicksort_modified.c
└── Chapter_1
│ ├── Question1_1
│ └── ChapQ1.1.c
│ ├── Question1_2
│ └── ChapQ1.2.c
│ ├── Question1_3
│ └── ChapQ1.3.c
│ └── Question1_4
│ └── ChapQ1.4.c
├── Go
├── Chapter 1
│ ├── Question1_1
│ │ ├── Question.go
│ │ └── Question_test.go
│ ├── Question1_2
│ │ ├── Question.go
│ │ └── Question_test.go
│ ├── Question1_3
│ │ ├── Question.go
│ │ ├── QuestionB.go
│ │ └── Question_test.go
│ ├── Question1_4
│ │ ├── Question.go
│ │ └── Question_test.go
│ ├── Question1_5
│ │ ├── Question.go
│ │ └── Question_test.go
│ ├── Question1_6
│ │ ├── Question.go
│ │ └── Question_test.go
│ ├── Question1_7
│ │ ├── Question.go
│ │ └── Question_test.go
│ └── Question1_8
│ │ ├── Question.go
│ │ └── Question_test.go
├── Chapter 2
│ ├── Question2_1
│ │ └── Question.go
│ ├── Question2_2
│ │ └── Question.go
│ ├── Question2_3
│ │ └── Question.go
│ ├── Question2_4
│ │ └── Question.go
│ ├── Question2_5
│ │ └── Question.go
│ ├── Question2_6
│ │ └── Question.go
│ ├── Question2_7
│ │ └── Question.go
│ ├── list
│ │ ├── list.go
│ │ └── list_test.go
│ └── stack
│ │ └── stack.go
└── Chapter 3
│ ├── Question3_1
│ └── Question.go
│ ├── Question3_2
│ └── Question.go
│ ├── Question3_3
│ └── Question.go
│ ├── Question3_4
│ └── Question.go
│ ├── Question3_5
│ └── Question.go
│ ├── Question3_6
│ └── Question.go
│ ├── Question3_7
│ └── Question.go
│ ├── list
│ ├── list.go
│ └── list_test.go
│ └── stack
│ └── stack.go
├── README.md
├── README.md.orig
├── Swift
├── Chapter 1
│ ├── Chapter 1.playground
│ │ ├── contents.xcplayground
│ │ ├── section-1.swift
│ │ └── timeline.xctimeline
│ └── Question 6
│ │ ├── README.md
│ │ └── Rotate.swift
├── Chapter 18
│ └── Question-1
│ │ ├── Question.swift
│ │ └── README.md
├── Chapter 2
│ └── Chapter 2.playground
│ │ ├── contents.xcplayground
│ │ ├── section-1.swift
│ │ └── timeline.xctimeline
├── Chapter 5
│ ├── Question-1
│ │ └── Question.swift
│ ├── Question-2
│ │ ├── Question.swift
│ │ ├── README.md
│ │ └── untitled
│ ├── Question-3
│ │ ├── Question.swift
│ │ └── README.md
│ ├── Question-4
│ │ └── ReadMe.md
│ ├── Question-5
│ │ ├── Question.swift
│ │ └── README.md
│ ├── Question-6
│ │ ├── Question.swift
│ │ └── README.md
│ └── Question-7
│ │ ├── Question5_7.swift
│ │ └── README.md
└── README.md
├── c++
├── Chapter 1
│ ├── Chapter 1.vcxproj
│ ├── Chapter 1.vcxproj.filters
│ ├── Misc
│ │ ├── SimpleHashTable.h
│ │ └── SimpleHashTable.inl
│ ├── Question1_1
│ │ ├── Question1_1.cpp
│ │ └── Question1_1.h
│ ├── Question1_2
│ │ ├── Question1_2.cpp
│ │ └── Question1_2.h
│ ├── Question1_3
│ │ ├── Question1_3.cpp
│ │ ├── Question1_3.h
│ │ ├── Question1_3_B.cpp
│ │ └── Question1_3_B.h
│ ├── Question1_4
│ │ ├── Question1_4.cpp
│ │ └── Question1_4.h
│ ├── Question1_5
│ │ ├── Question1_5.cpp
│ │ └── Question1_5.h
│ ├── Question1_6
│ │ ├── Question1_6.cpp
│ │ └── Question1_6.h
│ ├── Question1_7
│ │ ├── Question1_7.cpp
│ │ └── Question1_7.h
│ ├── Question1_8
│ │ ├── Question1_8.cpp
│ │ └── Question1_8.h
│ ├── Question2_1.h
│ ├── Question2_2.h
│ ├── Question2_3.h
│ ├── Question2_4.h
│ ├── Question2_5.h
│ ├── Question2_6.h
│ ├── Question2_7.h
│ └── main.cpp
├── Chapter 11
│ ├── Chapter11.h
│ ├── Chapter11_1.cpp
│ ├── Chapter11_2.cpp
│ ├── Chapter11_3.cpp
│ ├── Chapter11_5.cpp
│ ├── Chapter11_6.cpp
│ ├── Chapter11_7.cpp
│ └── Chapter11_8.cpp
├── Chapter 17
│ ├── Question17_1.cpp
│ ├── Question17_3.cpp
│ └── Question17_5.cpp
├── Chapter 2
│ ├── LinkedListClass
│ │ ├── LinkedList.cpp
│ │ └── LinkedList.h
│ ├── Question2_1.cpp
│ ├── Question2_2.cpp
│ ├── Question2_3.cpp
│ ├── Question2_4.cpp
│ ├── Question2_5.cpp
│ ├── Question2_6.cpp
│ └── Question2_7.cpp
├── Chapter 3
│ ├── Question3_1.cpp
│ ├── Question3_2.cpp
│ ├── Question3_3.cpp
│ ├── Question3_4.cpp
│ ├── Question3_5.cpp
│ ├── Question3_6.cpp
│ └── Question3_7.cpp
├── Chapter 4
│ ├── 4.2.in
│ ├── Question4_1.cpp
│ ├── Question4_2.cpp
│ ├── Question4_3.cpp
│ ├── Question4_4.cpp
│ ├── Question4_5.cpp
│ ├── Question4_6.cpp
│ ├── Question4_7.cpp
│ ├── Question4_8.cpp
│ └── Question4_9.cpp
├── Chapter 5
│ ├── Question5_1.cpp
│ ├── Question5_2.cpp
│ ├── Question5_3.cpp
│ ├── Question5_5.cpp
│ ├── Question5_6.cpp
│ ├── Question5_7.cpp
│ └── Question5_8.cpp
├── Chapter 9
│ ├── Question9_1.cpp
│ ├── Question9_10.cpp
│ ├── Question9_10.in
│ ├── Question9_11.cpp
│ ├── Question9_2.cpp
│ ├── Question9_3.cpp
│ ├── Question9_4.cpp
│ ├── Question9_5.cpp
│ ├── Question9_6.cpp
│ ├── Question9_7.cpp
│ ├── Question9_7.in
│ ├── Question9_8.cpp
│ └── Question9_9.cpp
└── ctci.sln
├── c-sharp
├── Chapter01
│ ├── Chapter01.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q01_1.cs
│ ├── Q01_2.cs
│ ├── Q01_3.cs
│ ├── Q01_4.cs
│ ├── Q01_5.cs
│ ├── Q01_6.cs
│ ├── Q01_7.cs
│ └── Q01_8.cs
├── Chapter02
│ ├── Chapter02.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q02_1.cs
│ ├── Q02_2.cs
│ ├── Q02_3.cs
│ ├── Q02_4.cs
│ ├── Q02_5.cs
│ ├── Q02_6.cs
│ ├── Q02_7.cs
│ └── Q02_Bonus1.cs
├── Chapter03
│ ├── Chapter03.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q03_1_A.cs
│ ├── Q03_1_B.cs
│ ├── Q03_2.cs
│ ├── Q03_3.cs
│ ├── Q03_4.cs
│ ├── Q03_5.cs
│ ├── Q03_6.cs
│ └── Q03_7.cs
├── Chapter04
│ ├── Chapter04.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q04_1.cs
│ ├── Q04_2.cs
│ ├── Q04_3.cs
│ ├── Q04_4.cs
│ ├── Q04_5.cs
│ ├── Q04_6.cs
│ ├── Q04_7.cs
│ ├── Q04_8.cs
│ └── Q04_9.cs
├── Chapter05
│ ├── Chapter05.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q05_1.cs
│ ├── Q05_2.cs
│ ├── Q05_3.cs
│ ├── Q05_5.cs
│ ├── Q05_6.cs
│ ├── Q05_7.cs
│ └── Q05_8.cs
├── Chapter07
│ ├── Chapter07.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q07_3.cs
│ ├── Q07_4.cs
│ ├── Q07_5.cs
│ ├── Q07_6.cs
│ └── Q07_7.cs
├── Chapter09
│ ├── Chapter09.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── Q09_6.cs
├── Chapter11
│ ├── Chapter11.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q11_1.cs
│ ├── Q11_2.cs
│ └── Q11_3.cs
├── Chapter17
│ ├── Chapter17.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q17_11.cs
│ ├── Q17_12.cs
│ ├── Q17_3.cs
│ └── Q17_4.cs
├── Chapter18
│ ├── Chapter18.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Q18_1.cs
│ ├── Q18_10.cs
│ ├── Q18_11.cs
│ ├── Q18_2.cs
│ └── Q18_9.cs
├── Introduction
│ ├── CompareBinaryToHex.cs
│ ├── Introduction.csproj
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── SwapMinMax.cs
├── ctci.Contracts
│ ├── IQuestion.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ └── ctci.Contracts.csproj
├── ctci.Library
│ ├── AssortedMethods.cs
│ ├── BTreePrinter.cs
│ ├── BitVector.cs
│ ├── LinkedListNode.cs
│ ├── Properties
│ │ └── AssemblyInfo.cs
│ ├── Set.cs
│ ├── TreeNode.cs
│ ├── Trie.cs
│ ├── TrieNode.cs
│ └── ctci.Library.csproj
├── ctci.sln
└── ctci
│ ├── Program.cs
│ ├── Properties
│ └── AssemblyInfo.cs
│ └── ctci.csproj
├── clojure
└── chapter01
│ ├── 01_01.clj
│ ├── 01_02.clj
│ ├── 01_03.clj
│ ├── 01_04.clj
│ └── 01_05.clj
├── dart
├── Chapter1
│ ├── Question1_1
│ │ └── question.dart
│ ├── Question1_2
│ │ └── question.dart
│ ├── Question1_3
│ │ ├── question.dart
│ │ └── question_b.dart
│ ├── Question1_4
│ │ └── question.dart
│ ├── Question1_5
│ │ └── question.dart
│ ├── Question1_6
│ │ └── question.dart
│ ├── Question1_7
│ │ └── question.dart
│ └── Question1_8
│ │ └── question.dart
├── Chapter11
│ ├── Introduction
│ │ ├── binary_search.dart
│ │ ├── merge_sort.dart
│ │ └── quick_sort.dart
│ ├── Question11_1
│ │ └── question.dart
│ ├── Question11_2
│ │ ├── question.dart
│ │ └── questionB.dart
│ ├── Question11_3
│ │ └── question.dart
│ ├── Question11_5
│ │ └── question.dart
│ ├── Question11_6
│ │ ├── question.dart
│ │ └── questionB.dart
│ ├── Question11_7
│ │ └── question.dart
│ └── Question11_8
│ │ └── question.dart
├── Chapter17
│ ├── Question17_1
│ │ └── question.dart
│ ├── Question17_10
│ │ ├── question.dart
│ │ └── questionString.dart
│ ├── Question17_11
│ │ ├── question.dart
│ │ └── questionB.dart
│ ├── Question17_12
│ │ └── question.dart
│ ├── Question17_13
│ │ ├── bi_node.dart
│ │ ├── questionA.dart
│ │ ├── questionB.dart
│ │ └── questionC.dart
│ ├── Question17_14
│ │ └── question.dart
│ ├── Question17_2
│ │ ├── question.dart
│ │ └── questionB.dart
│ ├── Question17_3
│ │ ├── questionA.dart
│ │ └── questionB.dart
│ ├── Question17_4
│ │ └── question.dart
│ ├── Question17_5
│ │ └── question.dart
│ ├── Question17_6
│ │ └── question.dart
│ ├── Question17_7
│ │ └── question.dart
│ ├── Question17_8
│ │ └── question.dart
│ └── Question17_9
│ │ └── question.dart
├── Chapter18
│ ├── Question18_1
│ │ └── question.dart
│ ├── Question18_10
│ │ └── question.dart
│ ├── Question18_11
│ │ ├── question.dart
│ │ ├── square_cell.dart
│ │ └── subsquare.dart
│ ├── Question18_12
│ │ ├── questionB.dart
│ │ └── questionC.dart
│ ├── Question18_13
│ │ ├── question.dart
│ │ ├── rectangle.dart
│ │ └── word_group.dart
│ ├── Question18_2
│ │ └── question.dart
│ ├── Question18_3
│ │ └── question.dart
│ ├── Question18_4
│ │ ├── question.dart
│ │ └── questionBrute.dart
│ ├── Question18_5
│ │ └── question.dart
│ ├── Question18_6
│ │ └── question.dart
│ ├── Question18_7
│ │ └── question.dart
│ ├── Question18_8
│ │ └── question.dart
│ └── Question18_9
│ │ ├── maxPQ.dart
│ │ ├── minPQ.dart
│ │ └── question.dart
├── Chapter2
│ ├── Question2_1
│ │ └── question.dart
│ ├── Question2_2
│ │ └── question.dart
│ ├── Question2_3
│ │ └── question.dart
│ ├── Question2_4
│ │ ├── question.dart
│ │ └── questionB.dart
│ ├── Question2_5
│ │ ├── questionA.dart
│ │ └── questionB.dart
│ ├── Question2_6
│ │ └── question.dart
│ └── Question2_7
│ │ ├── questionA.dart
│ │ └── questionB.dart
├── Chapter3
│ ├── Question3_1
│ │ ├── question.dart
│ │ └── questionB.dart
│ ├── Question3_2
│ │ └── question.dart
│ ├── Question3_3
│ │ └── question.dart
│ ├── Question3_4
│ │ └── question.dart
│ ├── Question3_5
│ │ └── question.dart
│ ├── Question3_6
│ │ └── question.dart
│ └── Question3_7
│ │ └── question.dart
├── Chapter4
│ ├── Question4_1
│ │ ├── question_brute.dart
│ │ └── question_improved.dart
│ ├── Question4_2
│ │ └── question.dart
│ ├── Question4_3
│ │ └── question.dart
│ ├── Question4_4
│ │ ├── question_bfs.dart
│ │ └── question_dfs.dart
│ ├── Question4_5
│ │ ├── question.dart
│ │ └── question_b.dart
│ ├── Question4_6
│ │ └── question.dart
│ ├── Question4_7
│ │ ├── question.dart
│ │ ├── question_b.dart
│ │ ├── question_c.dart
│ │ └── question_c_bad.dart
│ ├── Question4_8
│ │ └── question.dart
│ └── Question4_9
│ │ └── question.dart
├── Chapter5
│ ├── Question5_1
│ │ └── question.dart
│ ├── Question5_2
│ │ └── question.dart
│ ├── Question5_3
│ │ └── question.dart
│ ├── Question5_5
│ │ └── question.dart
│ ├── Question5_6
│ │ └── question.dart
│ ├── Question5_7
│ │ └── question.dart
│ └── Question5_8
│ │ └── question.dart
├── Chapter7
│ ├── Introduction
│ │ ├── prime_numbers.dart
│ │ └── sieve_of_eratosthenes.dart
│ ├── Question7_3
│ │ └── question.dart
│ ├── Question7_4
│ │ └── question.dart
│ ├── Question7_5
│ │ └── question.dart
│ ├── Question7_6
│ │ └── question.dart
│ └── Question7_7
│ │ ├── questionA.dart
│ │ └── questionB.dart
├── Chapter8
│ └── Question8_1
│ │ ├── black_jack_card.dart
│ │ ├── black_jack_game_automator.dart
│ │ ├── black_jack_hand.dart
│ │ ├── card.dart
│ │ ├── deck.dart
│ │ ├── hand.dart
│ │ ├── question.dart
│ │ └── suit.dart
├── Chapter9
│ ├── Introduction
│ │ ├── fibonacci.dart
│ │ └── fibonacci_fb.dart
│ ├── Question9_1
│ │ └── question.dart
│ ├── Question9_10
│ │ └── question.dart
│ ├── Question9_11
│ │ └── question.dart
│ ├── Question9_2
│ │ ├── questionDP.dart
│ │ └── questionR.dart
│ ├── Question9_3
│ │ ├── question.dart
│ │ └── questionB.dart
│ ├── Question9_4
│ │ └── question.dart
│ ├── Question9_5
│ │ └── question.dart
│ ├── Question9_6
│ │ ├── questionA.dart
│ │ └── questionB.dart
│ ├── Question9_7
│ │ └── question.dart
│ ├── Question9_8
│ │ └── question.dart
│ └── Question9_9
│ │ └── question.dart
├── README.md
└── utils
│ ├── assorted_methods.dart
│ ├── btree_printer.dart
│ ├── drandom.dart
│ ├── linked_list_node.dart
│ ├── tree_node.dart
│ └── trie.dart
├── go
├── README.md
├── chapter01
│ ├── question1.1
│ │ └── question1_1.go
│ ├── question1.3
│ │ └── question1_3.go
│ ├── question1.4
│ │ └── question1_4.go
│ ├── question1.5
│ │ └── question1_5.go
│ ├── question1.6
│ │ └── question1_6.go
│ ├── question1.7
│ │ └── question1_7.go
│ └── question1.8
│ │ └── question1_8.go
├── chapter02
│ ├── list
│ │ └── list.go
│ ├── question2.1
│ │ ├── question2_1.go
│ │ └── question2_1b.go
│ ├── question2.2
│ │ └── question2_2.go
│ ├── question2.3
│ │ └── question2_3.go
│ ├── question2.4
│ │ └── question2_4.go
│ ├── question2.5
│ │ └── question2_5.go
│ ├── question2.6
│ │ └── question2_6.go
│ ├── question2.7
│ │ └── question2_7.go
│ └── stack
│ │ └── stack.go
└── chapter04
│ ├── binarytree
│ └── binarytree.go
│ ├── question4.1
│ ├── question4_1.go
│ └── question4_1b.go
│ ├── question4.2
│ └── question4_2.go
│ ├── question4.3
│ └── question4_3.go
│ ├── question4.4
│ ├── question4_4.go
│ └── question4_4b.go
│ ├── question4.5
│ └── question4_5.go
│ ├── question4.6
│ └── question4_6.go
│ ├── question4.7
│ └── question4_7.go
│ ├── question4.8
│ └── question4_8.go
│ ├── question4.9
│ └── question4_9.go
│ ├── queue
│ └── queue.go
│ └── tree
│ └── tree.go
├── java
├── Chapter 1
│ ├── Question1_1
│ │ └── Question.java
│ ├── Question1_3
│ │ ├── Question.java
│ │ └── QuestionB.java
│ ├── Question1_4
│ │ └── Question.java
│ ├── Question1_5
│ │ └── Question.java
│ ├── Question1_6
│ │ └── Question.java
│ ├── Question1_7
│ │ └── Question.java
│ └── Question1_8
│ │ └── Question.java
├── Chapter 10
│ ├── Question10_2
│ │ ├── Machine.java
│ │ ├── Person.java
│ │ └── Server.java
│ ├── Question10_3
│ │ ├── Question.java
│ │ ├── QuestionB.java
│ │ └── input_file_q10_3.txt
│ ├── Question10_4
│ │ ├── BitSet.java
│ │ └── Question.java
│ └── Question10_7
│ │ ├── Cache.java
│ │ ├── Node.java
│ │ └── Question.java
├── Chapter 11
│ ├── Introduction
│ │ ├── BinarySearch.java
│ │ ├── MergeSort.java
│ │ └── Quicksort.java
│ ├── Question11_1
│ │ └── Question.java
│ ├── Question11_2
│ │ ├── AnagramComparator.java
│ │ ├── Question.java
│ │ └── QuestionB.java
│ ├── Question11_3
│ │ └── Question.java
│ ├── Question11_5
│ │ └── Question.java
│ ├── Question11_6
│ │ ├── .DS_Store
│ │ ├── Coordinate.java
│ │ ├── QuestionA.java
│ │ └── QuestionB.java
│ ├── Question11_7
│ │ ├── HtWt.java
│ │ └── Question.java
│ └── Question11_8
│ │ ├── IntComparable.java
│ │ ├── Question.java
│ │ └── RankNode.java
├── Chapter 14
│ ├── Introduction
│ │ ├── Ambiguous.java
│ │ ├── Circle.java
│ │ ├── Introduction.java
│ │ ├── IntroductionCollections.java
│ │ ├── IntroductionOverriding.java
│ │ ├── Shape.java
│ │ └── Square.java
│ ├── Question14_1
│ │ └── Question.java
│ ├── Question14_5
│ │ ├── Question.java
│ │ └── Rectangle.java
│ └── Question14_6
│ │ ├── CircularArray.java
│ │ └── Question.java
├── Chapter 16
│ ├── IntroductionA
│ │ ├── ExampleA.java
│ │ └── RunnableThreadExample.java
│ ├── IntroductionB
│ │ ├── ExampleB.java
│ │ └── ThreadExample.java
│ ├── IntroductionLocks
│ │ ├── Intro.java
│ │ ├── LockedATM.java
│ │ ├── MyClass.java
│ │ └── NoLockATM.java
│ ├── IntroductionSynchronization
│ │ ├── Intro.java
│ │ ├── MyClass.java
│ │ └── MyObject.java
│ ├── IntroductionSynchronizedBlocks
│ │ ├── Intro.java
│ │ ├── MyClass.java
│ │ └── MyObject.java
│ ├── IntroductionWaitNotify
│ │ ├── Intro.java
│ │ ├── MyClass.java
│ │ └── MyObject.java
│ ├── Question16_3
│ │ ├── Chopstick.java
│ │ ├── Philosopher.java
│ │ └── Question.java
│ ├── Question16_4
│ │ ├── LockFactory.java
│ │ ├── LockNode.java
│ │ └── Question.java
│ ├── Question16_5
│ │ ├── Foo.java
│ │ ├── FooBad.java
│ │ ├── MyThread.java
│ │ └── Question.java
│ └── Question16_6
│ │ ├── Foo.java
│ │ ├── MyThread.java
│ │ └── Question.java
├── Chapter 17
│ ├── Question17_1
│ │ └── Question.java
│ ├── Question17_10
│ │ ├── Attribute.java
│ │ ├── Element.java
│ │ ├── QuestionOO.java
│ │ └── QuestionString.java
│ ├── Question17_11
│ │ ├── Question.java
│ │ └── QuestionB.java
│ ├── Question17_12
│ │ └── Question.java
│ ├── Question17_13
│ │ ├── BiNode.java
│ │ ├── QuestionA.java
│ │ ├── QuestionB.java
│ │ └── QuestionC.java
│ ├── Question17_14
│ │ ├── Question.java
│ │ └── Result.java
│ ├── Question17_2
│ │ ├── Question.java
│ │ └── QuestionB.java
│ ├── Question17_3
│ │ ├── QuestionA.java
│ │ └── QuestionB.java
│ ├── Question17_4
│ │ └── Question.java
│ ├── Question17_5
│ │ └── Question.java
│ ├── Question17_6
│ │ └── Question.java
│ ├── Question17_7
│ │ └── Question.java
│ ├── Question17_8
│ │ └── Question.java
│ └── Question17_9
│ │ └── Question.java
├── Chapter 18
│ ├── Question18_1
│ │ └── Question.java
│ ├── Question18_10
│ │ └── Question.java
│ ├── Question18_11
│ │ ├── Question.java
│ │ ├── QuestionEff.java
│ │ ├── SquareCell.java
│ │ └── Subsquare.java
│ ├── Question18_12
│ │ ├── QuestionB.java
│ │ └── QuestionC.java
│ ├── Question18_13
│ │ ├── Question.java
│ │ ├── Rectangle.java
│ │ └── WordGroup.java
│ ├── Question18_2
│ │ └── Question.java
│ ├── Question18_3
│ │ ├── Question.java
│ │ └── QuestionAlternate.java
│ ├── Question18_4
│ │ ├── Question.java
│ │ └── QuestionBrute.java
│ ├── Question18_5
│ │ └── Question.java
│ ├── Question18_6
│ │ ├── Parts.java
│ │ └── QuestionC.java
│ ├── Question18_7
│ │ ├── LengthComparator.java
│ │ └── Question.java
│ ├── Question18_8
│ │ ├── Question.java
│ │ ├── SuffixTree.java
│ │ └── SuffixTreeNode.java
│ └── Question18_9
│ │ ├── MaxHeapComparator.java
│ │ ├── MinHeapComparator.java
│ │ └── Question.java
├── Chapter 2
│ ├── Question2_1
│ │ └── Question.java
│ ├── Question2_2
│ │ ├── Cpp Link
│ │ ├── IntWrapper.java
│ │ ├── Question.java
│ │ └── Result.java
│ ├── Question2_3
│ │ └── Question.java
│ ├── Question2_4
│ │ ├── Question.java
│ │ ├── QuestionB.java
│ │ └── QuestionC.java
│ ├── Question2_5
│ │ ├── PartialSum.java
│ │ ├── QuestionA.java
│ │ └── QuestionB.java
│ ├── Question2_6
│ │ └── Question.java
│ └── Question2_7
│ │ ├── Question.java
│ │ └── QuestionB.java
├── Chapter 3
│ ├── Question3_1
│ │ ├── FullStackException.java
│ │ ├── Question.java
│ │ ├── QuestionB.java
│ │ └── StackData.java
│ ├── Question3_2
│ │ ├── NodeWithMin.java
│ │ ├── Question.java
│ │ ├── StackWithMin.java
│ │ └── StackWithMin2.java
│ ├── Question3_3
│ │ ├── Node.java
│ │ ├── Question.java
│ │ ├── SetOfStacks.java
│ │ └── Stack.java
│ ├── Question3_4
│ │ ├── Question.java
│ │ └── Tower.java
│ ├── Question3_5
│ │ ├── MyQueue.java
│ │ └── Question.java
│ ├── Question3_6
│ │ └── Question.java
│ └── Question3_7
│ │ ├── Animal.java
│ │ ├── AnimalQueue.java
│ │ ├── Cat.java
│ │ ├── Dog.java
│ │ └── Question.java
├── Chapter 4
│ ├── Question4_1
│ │ ├── QuestionBrute.java
│ │ └── QuestionImproved.java
│ ├── Question4_2
│ │ ├── Graph.java
│ │ ├── Node.java
│ │ └── Question.java
│ ├── Question4_3
│ │ └── Question.java
│ ├── Question4_4
│ │ ├── QuestionBFS.java
│ │ └── QuestionDFS.java
│ ├── Question4_5
│ │ ├── IntWrapper.java
│ │ ├── Question.java
│ │ └── QuestionB.java
│ ├── Question4_6
│ │ └── Question.java
│ ├── Question4_7
│ │ ├── Question.java
│ │ ├── QuestionB.java
│ │ ├── QuestionC.java
│ │ └── QuestionCBad.java
│ ├── Question4_8
│ │ └── Question.java
│ └── Question4_9
│ │ └── Question.java
├── Chapter 5
│ ├── Question5_1
│ │ └── Question.java
│ ├── Question5_2
│ │ └── Question.java
│ ├── Question5_3
│ │ └── Question.java
│ ├── Question5_5
│ │ └── Question.java
│ ├── Question5_6
│ │ └── Question.java
│ ├── Question5_7.zip
│ ├── Question5_7
│ │ ├── BitInteger.java
│ │ └── Question.java
│ ├── Question5_8
│ │ └── Question.java
│ └── Sample_Code
│ │ └── Sample_Code.java
├── Chapter 7
│ ├── Introduction
│ │ ├── PrimeNumbers.java
│ │ └── SieveOfEratosthenes.java
│ ├── Question7_3
│ │ ├── Line.java
│ │ └── Question.java
│ ├── Question7_4
│ │ └── Question.java
│ ├── Question7_5
│ │ ├── Line.java
│ │ ├── Point.java
│ │ ├── Question.java
│ │ ├── Square Cut Tester - Chapter 10, Problem 5.xlsx
│ │ └── Square.java
│ ├── Question7_6
│ │ ├── GraphPoint.java
│ │ ├── Line.java
│ │ └── Question.java
│ └── Question7_7
│ │ ├── QuestionA.java
│ │ └── QuestionB.java
├── Chapter 8
│ ├── Question8_1
│ │ ├── BlackJackCard.java
│ │ ├── BlackJackGameAutomator.java
│ │ ├── BlackJackHand.java
│ │ ├── Card.java
│ │ ├── Deck.java
│ │ ├── Hand.java
│ │ ├── Question.java
│ │ └── Suit.java
│ ├── Question8_10
│ │ ├── Cell.java
│ │ ├── Dummy.java
│ │ ├── Hash.java
│ │ └── Question.java
│ ├── Question8_2
│ │ ├── Call.java
│ │ ├── CallHandler.java
│ │ ├── Caller.java
│ │ ├── Director.java
│ │ ├── Employee.java
│ │ ├── Manager.java
│ │ ├── Rank.java
│ │ ├── Respondent.java
│ │ └── Test.java
│ ├── Question8_3
│ │ ├── CD.java
│ │ ├── CDPlayer.java
│ │ ├── JukeBox.java
│ │ ├── Playlist.java
│ │ ├── Song.java
│ │ ├── SongSelector.java
│ │ └── User.java
│ ├── Question8_4
│ │ ├── Bus.java
│ │ ├── Car.java
│ │ ├── Level.java
│ │ ├── Motorcycle.java
│ │ ├── ParkingLot.java
│ │ ├── ParkingSpot.java
│ │ ├── Question.java
│ │ ├── Vehicle.java
│ │ └── VehicleSize.java
│ ├── Question8_5
│ │ ├── Book.java
│ │ ├── Display.java
│ │ ├── Library.java
│ │ ├── OnlineReaderSystem.java
│ │ ├── User.java
│ │ └── UserManager.java
│ ├── Question8_7
│ │ ├── AddRequest.java
│ │ ├── Conversation.java
│ │ ├── GroupChat.java
│ │ ├── Message.java
│ │ ├── PrivateChat.java
│ │ ├── RequestStatus.java
│ │ ├── System.java
│ │ ├── User.java
│ │ ├── UserManager.java
│ │ ├── UserStatus.java
│ │ └── UserStatusType.java
│ ├── Question8_8
│ │ ├── Automator.java
│ │ ├── Board.java
│ │ ├── Color.java
│ │ ├── Direction.java
│ │ ├── Game.java
│ │ ├── Location.java
│ │ ├── Piece.java
│ │ ├── Player.java
│ │ └── Question.java
│ └── Question8_9
│ │ ├── Directory.java
│ │ ├── Entry.java
│ │ ├── File.java
│ │ └── Question.java
├── Chapter 9
│ ├── Introduction
│ │ ├── Fibonacci.java
│ │ └── FibonacciFB.java
│ ├── Question9_1
│ │ └── Question.java
│ ├── Question9_10
│ │ ├── Box.java
│ │ └── Question.java
│ ├── Question9_11
│ │ └── Question.java
│ ├── Question9_2
│ │ ├── QuestionDP.java
│ │ └── QuestionR.java
│ ├── Question9_3
│ │ ├── Question.java
│ │ └── QuestionB.java
│ ├── Question9_4
│ │ └── Question.java
│ ├── Question9_5
│ │ └── Question.java
│ ├── Question9_6
│ │ ├── QuestionA.java
│ │ └── QuestionB.java
│ ├── Question9_7
│ │ └── Question.java
│ ├── Question9_8
│ │ └── Question.java
│ └── Question9_9
│ │ └── Question.java
├── CtCILibrary
│ └── CtCILibrary
│ │ ├── AssortedMethods.java
│ │ ├── BTreePrinter.java
│ │ ├── BitVector.java
│ │ ├── LinkedListNode.java
│ │ ├── TreeNode.java
│ │ ├── Trie.java
│ │ └── TrieNode.java
└── Introduction
│ ├── CompareBinaryToHex
│ └── CompareBinaryToHex.java
│ └── SwapMinMax
│ └── SwapMinMax.java
├── javascript
├── README.md
├── lib
│ ├── data-structures
│ │ ├── chapter-1
│ │ │ ├── 1_1.js
│ │ │ ├── 1_2.js
│ │ │ ├── 1_3.js
│ │ │ └── 1_8.js
│ │ ├── chapter-2
│ │ │ ├── 2_1.js
│ │ │ ├── 2_2.js
│ │ │ └── 2_3.js
│ │ ├── chapter-3
│ │ │ └── 3_5.js
│ │ ├── chapter-9
│ │ │ └── 9_1.js
│ │ └── linked-list
│ │ │ ├── doublyLinkedList.js
│ │ │ ├── node.js
│ │ │ └── singlyLinkedList.js
│ └── index.js
├── package.json
└── test
│ ├── data-structures
│ ├── chapter-1
│ │ ├── 1_1_Spec.js
│ │ ├── 1_2_Spec.js
│ │ ├── 1_3_Spec.js
│ │ └── 1_8_Spec.js
│ ├── chapter-2
│ │ ├── 2_1_Spec.js
│ │ ├── 2_2_Spec.js
│ │ └── 2_3_Spec.js
│ ├── chapter-3
│ │ └── 3_5_Spec.js
│ ├── chapter-9
│ │ └── 9_1_Spec.js
│ └── linked-list
│ │ ├── doublyLinkedListSpec.js
│ │ ├── nodeSpec.js
│ │ └── singlyLinkedListSpec.js
│ └── test_helper.js
├── objective c
├── Chapter1
│ ├── Question1-5
│ │ ├── Question1-5.xcodeproj
│ │ │ ├── project.pbxproj
│ │ │ ├── project.xcworkspace
│ │ │ │ ├── contents.xcworkspacedata
│ │ │ │ └── xcshareddata
│ │ │ │ │ └── Question1-5.xccheckout
│ │ │ └── xcuserdata
│ │ │ │ └── rmoniz.xcuserdatad
│ │ │ │ └── xcdebugger
│ │ │ │ └── Breakpoints_v2.xcbkptlist
│ │ └── Question1-5
│ │ │ ├── Question1-5-Prefix.pch
│ │ │ └── main.m
│ ├── Question1-6
│ │ ├── Question1-6.xcodeproj
│ │ │ ├── project.pbxproj
│ │ │ └── project.xcworkspace
│ │ │ │ ├── contents.xcworkspacedata
│ │ │ │ └── xcshareddata
│ │ │ │ └── Question1-6.xccheckout
│ │ └── Question1-6
│ │ │ ├── Question1-6-Prefix.pch
│ │ │ └── main.m
│ ├── Question1_1
│ │ ├── Question1_1.xcodeproj
│ │ │ ├── project.pbxproj
│ │ │ ├── project.xcworkspace
│ │ │ │ ├── contents.xcworkspacedata
│ │ │ │ └── xcshareddata
│ │ │ │ │ └── Question1_1.xccheckout
│ │ │ └── xcuserdata
│ │ │ │ └── rmoniz.xcuserdatad
│ │ │ │ └── xcdebugger
│ │ │ │ └── Breakpoints_v2.xcbkptlist
│ │ └── Question1_1
│ │ │ ├── Question1_1-Prefix.pch
│ │ │ ├── Question1_1.1
│ │ │ └── main.m
│ ├── Question1_3
│ │ ├── Question1_3.xcodeproj
│ │ │ ├── project.pbxproj
│ │ │ ├── project.xcworkspace
│ │ │ │ ├── contents.xcworkspacedata
│ │ │ │ └── xcshareddata
│ │ │ │ │ └── Question1_3.xccheckout
│ │ │ └── xcuserdata
│ │ │ │ └── rmoniz.xcuserdatad
│ │ │ │ └── xcdebugger
│ │ │ │ └── Breakpoints_v2.xcbkptlist
│ │ └── Question1_3
│ │ │ ├── Question1_3-Prefix.pch
│ │ │ └── main.m
│ └── Question1_4
│ │ ├── Question1_4.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ └── Question1_4.xccheckout
│ │ └── xcuserdata
│ │ │ └── rmoniz.xcuserdatad
│ │ │ └── xcdebugger
│ │ │ └── Breakpoints_v2.xcbkptlist
│ │ └── Question1_4
│ │ ├── Question1_4-Prefix.pch
│ │ └── main.m
├── CtCILibrary
│ └── CtCILibrary
│ │ ├── AssortedMethods.h
│ │ └── AssortedMethods.m
├── Introduction
│ ├── CompareBinaryToHex
│ │ ├── CompareBinaryToHex.xcodeproj
│ │ │ ├── project.pbxproj
│ │ │ └── project.xcworkspace
│ │ │ │ ├── contents.xcworkspacedata
│ │ │ │ └── xcshareddata
│ │ │ │ └── CompareBinaryToHex.xccheckout
│ │ └── CompareBinaryToHex
│ │ │ ├── CompareBinaryToHex-Prefix.pch
│ │ │ ├── CompareBinaryToHex.1
│ │ │ ├── CompareBinaryToHex.h
│ │ │ ├── CompareBinaryToHex.m
│ │ │ └── main.m
│ └── SwapMinMax
│ │ ├── SwapMinMax.xcodeproj
│ │ ├── project.pbxproj
│ │ ├── project.xcworkspace
│ │ │ ├── contents.xcworkspacedata
│ │ │ └── xcshareddata
│ │ │ │ └── SwapMinMax.xccheckout
│ │ └── xcuserdata
│ │ │ └── rmoniz.xcuserdatad
│ │ │ └── xcdebugger
│ │ │ └── Breakpoints_v2.xcbkptlist
│ │ └── SwapMinMax
│ │ ├── SwapMinMax-Prefix.pch
│ │ ├── SwapMinMax.1
│ │ └── main.m
└── README.txt
├── python
├── Chapter 1
│ ├── Question1_1
│ │ ├── 1-unique.py
│ │ ├── ChapQ1.1.py
│ │ ├── alluniq.py
│ │ └── testalluniq.py
│ ├── Question1_2
│ │ ├── ChapQ1.2.py
│ │ ├── revstr.py
│ │ └── testrevstr.py
│ ├── Question1_3
│ │ ├── ChapQ1.3.py
│ │ ├── anagram.py
│ │ └── testanagram.py
│ ├── Question1_4
│ │ ├── ChapQ1.4.py
│ │ ├── Q1_4.py
│ │ ├── replace.py
│ │ └── testreplace.py
│ ├── Question1_5
│ │ ├── ChapQ1.5.py
│ │ ├── compress.py
│ │ └── testcompress.py
│ ├── Question1_6
│ │ ├── ChapQ1.6.py
│ │ ├── rotateimg.py
│ │ └── testrotate.py
│ ├── Question1_7
│ │ └── ChapQ1.7.py
│ └── Question1_8
│ │ └── ChapQ1.8.py
├── Chapter 2
│ ├── Question2_1.py
│ ├── Question2_2.py
│ ├── Question2_3.py
│ ├── Question2_4.py
│ ├── Question2_5.py
│ ├── Question2_6.py
│ ├── Question2_7.py
│ └── classes
│ │ ├── LinkedList.py
│ │ ├── LinkedList.pyc
│ │ ├── __init__.py
│ │ └── __init__.pyc
├── Chapter 3
│ ├── Question3_1
│ │ └── Q3_1.py
│ ├── Question3_2
│ │ └── ChapQ3.2.py
│ ├── Question3_3
│ │ └── Q3_3.py
│ ├── Question3_4
│ │ └── Q3_4.py
│ ├── Question3_5
│ │ ├── 3_5.py
│ │ └── ChapQ3.5.py
│ ├── Question3_6
│ │ └── ChapQ3.6.py
│ └── Question3_7
│ │ └── ChapQ3.7.py
├── Chapter 4
│ ├── Question4_1
│ │ └── ChapQ4.1.py
│ ├── Question4_2
│ │ └── ChapQ4.2.py
│ ├── Question4_3
│ │ └── ChapQ4.3.py
│ ├── Question4_4
│ │ └── ChapQ4.4.py
│ ├── Question4_5
│ │ └── ChapQ4.5.py
│ ├── Question4_6
│ │ └── ChapQ4.6.py
│ ├── Question4_7
│ │ ├── BinaryTreeNode.py
│ │ └── Q4_7.py
│ ├── Question4_8
│ │ └── ChapQ4.8.py
│ └── Question4_9
│ │ ├── BinaryTreeNode.py
│ │ └── Q4_9.py
└── Chapter 9
│ ├── Question9_01
│ └── staircase.py
│ ├── Question9_02
│ └── robot_paths.py
│ ├── Question9_03
│ ├── magic_index.py
│ └── magic_index_followup.py
│ ├── Question9_04
│ └── subsets.py
│ ├── Question9_05
│ └── permutations.py
│ ├── Question9_06
│ └── parentheses.py
│ ├── Question9_07
│ └── paint_fill.py
│ ├── Question9_08
│ └── change_making.py
│ ├── Question9_09
│ └── queens_problem.py
│ ├── Question9_10
│ └── tallest_stack.py
│ └── Question9_11
│ └── parenthesizing.py
├── ruby
├── Gemfile
├── Gemfile.lock
├── lib
│ └── data-structures
│ │ ├── chapter-1
│ │ ├── 1_1.rb
│ │ ├── 1_5.rb
│ │ └── 1_8.rb
│ │ ├── chapter-2
│ │ ├── 2_1.rb
│ │ ├── 2_3.rb
│ │ ├── 2_4.rb
│ │ └── 2_6.rb
│ │ ├── hash-table
│ │ └── hash_table.rb
│ │ └── linked-list
│ │ ├── doubly_linked_list.rb
│ │ ├── node.rb
│ │ └── singly_linked_list.rb
└── spec
│ ├── data-structures
│ ├── chapter-1
│ │ ├── 1_1_spec.rb
│ │ ├── 1_5_spec.rb
│ │ └── 1_8_spec.rb
│ ├── chapter-2
│ │ ├── 2_1_spec.rb
│ │ ├── 2_4_spec.rb
│ │ └── 2_6_spec.rb
│ ├── hash-table
│ │ └── hash_table_spec.rb
│ └── linked-list
│ │ ├── doubly_linked_list_spec.rb
│ │ ├── node_spec.rb
│ │ └── singly_linked_list_spec.rb
│ └── spec_helper.rb
└── scala
├── build.sbt
└── src
├── main
└── scala
│ ├── chapter1
│ └── Chapter1Solution.scala
│ ├── chapter2
│ └── Chapter2Solution.scala
│ ├── chapter3
│ └── Chapter3Solution.scala
│ └── chapter4
│ └── Chapter4Solution.scala
└── test
└── scala
├── chapter1
└── chapter1Test.scala
└── chapter2
└── chapter2Test.scala
/Go/Chapter 1/Question1_1/Question.go:
--------------------------------------------------------------------------------
1 | package Question1_1
2 |
3 | // using a bitvector
4 | func isUniqueChars(str string) bool {
5 | if len(str) > 128 {
6 | return false
7 | }
8 | var checker uint = 0; // use this int as a bit vector
9 | for _, char := range str {
10 | val := uint(char) - uint('a')
11 | if ((checker & (1 << val)) > 0) {
12 | return false
13 | }
14 | checker |= (1 << val)
15 | }
16 | return true
17 | }
18 |
19 | // using a boolean array
20 | func isUniqueChars2(str string) bool {
21 | if len(str) > 128 {
22 | return false
23 | }
24 | var char_set [128]bool // every bool represents if a character was seen
25 | for _, val := range str {
26 | if char_set[val] {
27 | return false
28 | }
29 | char_set[val] = true
30 | }
31 | return true
32 | }
33 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_1/Question_test.go:
--------------------------------------------------------------------------------
1 | package Question1_1
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestIsUniqueChars(t *testing.T) {
8 | cases := []struct {
9 | input string
10 | expect bool
11 | }{
12 | {"abcd", true},
13 | {"", true},
14 | {`_\/,"'.;`, true},
15 | {"abca", false},
16 | {"aaaa", false},
17 | }
18 |
19 | for _, thisCase := range cases {
20 | result := isUniqueChars(thisCase.input)
21 | if result != thisCase.expect {
22 | t.Errorf("isUniqueChars: input %q, expect %v, but got %v\n", thisCase.input, thisCase.expect, result)
23 | }
24 | result2 := isUniqueChars2(thisCase.input)
25 | if result2 != thisCase.expect {
26 | t.Errorf("isUniqueChars2: input %q, expect %v, but got %v\n", thisCase.input, thisCase.expect, result2)
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_2/Question.go:
--------------------------------------------------------------------------------
1 | package Question1_2
2 |
3 | // function to reverse a C style string, by returning a new reversed string
4 | func reverse(str string) string {
5 | length := len(str)
6 | revArr := []byte(str)
7 | for i := length / 2; i >= 0; i-- {
8 | revArr[i], revArr[length-i-1] = revArr[length-i-1], revArr[i]
9 | }
10 | return string(revArr)
11 | }
12 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_2/Question_test.go:
--------------------------------------------------------------------------------
1 | package Question1_2
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestReverse(t *testing.T) {
8 | cases := []struct {
9 | input string
10 | expect string
11 | }{
12 | {"abcd", "dcba"},
13 | {"abcde", "edcba"},
14 | }
15 |
16 | for _, thisCase := range cases {
17 | result := reverse(thisCase.input)
18 | if result != thisCase.expect {
19 | t.Errorf("reverse: input %q, expect %q, but got %q\n", thisCase.input, thisCase.expect, result)
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_3/Question.go:
--------------------------------------------------------------------------------
1 | package Question1_3
2 | import "sort"
3 |
4 | type sortRunes []rune
5 |
6 | // have to define the three methods for native sort to work
7 | func (s sortRunes) Less(i, j int) bool {
8 | return s[i] < s[j]
9 | }
10 |
11 | func (s sortRunes) Swap(i, j int) {
12 | s[i], s[j] = s[j], s[i]
13 | }
14 |
15 | func (s sortRunes) Len() int {
16 | return len(s)
17 | }
18 |
19 | func SortString(s string) string {
20 | r := []rune(s)
21 | sort.Sort(sortRunes(r))
22 | return string(r)
23 | }
24 |
25 | /* Given two strings, decide if one is a permutation of the other */
26 | func permutation(str1, str2 string) bool {
27 | // if they are anagrams, they will have the same characters
28 | // hence comparing if their sorted version is equal gives the result
29 | return SortString(str1) == SortString(str2)
30 | }
31 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_3/QuestionB.go:
--------------------------------------------------------------------------------
1 | package Question1_3
2 |
3 | /* Given two strings, decide if one is a permutation of the other */
4 | func permutation (str1, str2 string) bool {
5 | if len(str1) != len(str2) {
6 | return false
7 | }
8 | count1 := make([]int) //declare a map of rune to int
9 | // For each character in input1 string, increment count
10 | for _ , v := range str1 {
11 | count1[rune(v)]++
12 | }
13 | // For each character in input2 string, decrement count in the count1 map
14 | // the count becomes less than 0, if there is more count in second string or
15 | // if that character was not present in string1
16 | for _ , v := range str2 {
17 | c := rune(v)
18 | count1[c]--
19 | if count1[c] < 0 {
20 | return false
21 | }
22 | }
23 | return true
24 | }
25 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_3/Question_test.go:
--------------------------------------------------------------------------------
1 | package Question1_3
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestPermutation(t *testing.T) {
8 | cases := []struct {
9 | input1 string
10 | input2 string
11 | expect bool
12 | }{
13 | {"apple", "papel", true},
14 | {"carrot", "tarroc", true},
15 | {"hello", "llloh", false},
16 | }
17 | for _, thisCase := range cases {
18 | result := permutation(thisCase.input1, thisCase.input2)
19 | if result != thisCase.expect {
20 | t.Errorf("reverse: input (%q, %q), expected %v, but got %v\n",
21 | thisCase.input1, thisCase.input2, thisCase.expect, result)
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_4/Question.go:
--------------------------------------------------------------------------------
1 | package Question1_4
2 |
3 | // method to replace all spaces in a string with ‘%20’
4 | // assuming that the string has sufficient space at the end
5 | func ReplaceSpace(charsArr []rune, originalLen int) {
6 | countSpaces := 0
7 | for i := 0; i < originalLen; i++ {
8 | if charsArr[i] == rune(' ') {
9 | countSpaces++
10 | }
11 | }
12 | index := len(charsArr)
13 | for i := originalLen-1; i >= 0; i-- {
14 | if charsArr[i] == rune(' ') {
15 | charsArr[index-1] = '0';
16 | charsArr[index-2] = '2';
17 | charsArr[index-3] = '%';
18 | index = index-3;
19 | } else {
20 | charsArr[index-1] = charsArr[i]
21 | index--
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_5/Question_test.go:
--------------------------------------------------------------------------------
1 | package Question1_5
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestCompress(t *testing.T) {
8 | cases := []struct {
9 | input string
10 | expect string
11 | }{
12 | {"aabcccccaaa", `a2b1c5a3`},
13 | {"zxy", `zxy`},
14 | }
15 | for _, thisCase := range cases {
16 | result := compress(thisCase.input)
17 | if result != thisCase.expect {
18 | t.Errorf("Compress: input %q, expected %q, but got %q\n",
19 | thisCase.input, thisCase.expect, result)
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_6/Question_test.go:
--------------------------------------------------------------------------------
1 | package Question1_6
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestRotate90(t *testing.T) {
8 | cases := []struct {
9 | input matrixNN
10 | expect matrixNN
11 | }{
12 | { matrixNN{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} ,
13 | matrixNN{{7, 4, 1}, {8, 5, 2}, {9, 6, 3}} },
14 | { matrixNN{ {1, 2, 3, 4}, { 5, 6, 7, 8}, { 9, 10, 11, 12 }, {13, 14, 15, 16} },
15 | matrixNN{ {13, 9, 5, 1}, {14, 10, 6, 2}, {15, 11, 7, 3}, {16, 12, 8, 4} } },
16 | }
17 |
18 | for _, thisCase := range cases {
19 | input := thisCase.input
20 | thisCase.input.rotate90()
21 | result := thisCase.input
22 | if (!result.compare( thisCase.expect )) {
23 | t.Errorf("\n__________\nRotate90: \ninput %v \nexpected %v\n but got %v \n______________", input, thisCase.expect, result)
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_7/Question_test.go:
--------------------------------------------------------------------------------
1 | package Question1_7
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestSetZeroes(t *testing.T) {
8 | cases := []struct {
9 | input matrixMN
10 | expect matrixMN
11 | }{
12 | { matrixMN{{1, 2, 3}, {4, 0, 6}, {7, 8, 9}} ,
13 | matrixMN{{1, 0, 3}, {0, 0, 0}, {7, 0, 9}} },
14 | { matrixMN{ {1, 2, 3, 0}, { 5, 6, 7, 8}, { 9, 10, 11, 12 } },
15 | matrixMN{ {0, 0, 0, 0}, {5, 6, 7, 0}, {9, 10, 11, 0} } },
16 | }
17 |
18 | for _, thisCase := range cases {
19 | input := thisCase.input
20 | thisCase.input.setZeroes()
21 | result := thisCase.input
22 | if (!result.compare( thisCase.expect )) {
23 | t.Errorf("\n__________\nRotate90: \ninput %v \nexpected %v\n but got %v \n______________", input, thisCase.expect, result)
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_8/Question.go:
--------------------------------------------------------------------------------
1 | package Question1_8
2 |
3 | /*
4 | * Assume you have a method isSubstring which checks if one word is a
5 | * substring of another. Given two strings, s1 and s2, write code to check
6 | * if s2 is a rotation of s1 using only one call to isSubstring
7 | * (e.g., "waterbottle" is a rotation of "erbottlewat").
8 | */
9 |
10 | import (
11 | "strings"
12 | )
13 |
14 | func isRotation(s1, s2 string) bool {
15 | length1 := len(s1)
16 | if(length1 == len(s2) && length1 > 0) {
17 | /* Double the original string and check whether the rotated is a substring of it*/
18 | s1s1 := s1+s1
19 | if strings.Contains(s1s1, s2){
20 | return true
21 | }
22 | }
23 | return false
24 | }
25 |
--------------------------------------------------------------------------------
/Go/Chapter 1/Question1_8/Question_test.go:
--------------------------------------------------------------------------------
1 | package Question1_8
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestIsRotation(t *testing.T) {
8 | cases := []struct {
9 | input []string
10 | expect bool
11 | }{
12 | { []string{"apple", "pleap"} , true },
13 | { []string{"waterbottle", "erbottlewat"}, true },
14 | { []string{"camera", "macera"}, false },
15 | { []string{"santhosh", "@santhosh"}, false},
16 | }
17 |
18 | for _, thisCase := range cases {
19 | input := thisCase.input
20 | result := isRotation(input[0], input[1])
21 | if (result != thisCase.expect) {
22 | t.Errorf("IsRotation: input %q expected %v but got %v", input, thisCase.expect, result)
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/Go/Chapter 2/list/list_test.go:
--------------------------------------------------------------------------------
1 | package list
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestLength(t *testing.T) {
8 | for i := 1; i < 10; i++ {
9 | l := RandomLinkedList(i, 1, 10)
10 | result := l.Len()
11 | if (result != i) {
12 | t.Errorf("Length: Got-%v Expected-%v\n", result, i)
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/Go/Chapter 2/stack/stack.go:
--------------------------------------------------------------------------------
1 | package stack // simple LIFO stack
2 |
3 | type Stack struct {
4 | top *Element
5 | size int
6 | }
7 |
8 | type Element struct {
9 | value int // All types satisfy the empty interface, so we can store anything here.
10 | next *Element
11 | }
12 |
13 | // Return the stack's length
14 | func (s *Stack) Len() int {
15 | return s.size
16 | }
17 |
18 | // Push a new element onto the stack
19 | func (s *Stack) Push(value int) {
20 | s.top = &Element{value, s.top}
21 | s.size++
22 | }
23 |
24 | // Remove the top element from the stack and return it's value
25 | // If the stack is empty, return nil
26 | func (s *Stack) Pop() (value int) {
27 | if s.size > 0 {
28 | value, s.top = s.top.value, s.top.next
29 | s.size--
30 | return value
31 | }
32 | return -1
33 | }
34 |
--------------------------------------------------------------------------------
/Go/Chapter 3/list/list_test.go:
--------------------------------------------------------------------------------
1 | package list
2 |
3 | import (
4 | "testing"
5 | )
6 |
7 | func TestLength(t *testing.T) {
8 | for i := 1; i < 10; i++ {
9 | l := RandomLinkedList(i, 1, 10)
10 | result := l.Len()
11 | if (result != i) {
12 | t.Errorf("Length: Got-%v Expected-%v\n", result, i)
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ctci
2 | ====
3 |
4 | Solutions for "Cracking the Coding Interview v5"
5 |
6 | Adding equivalent solutions in Objective-C
7 | Adding my own solutions
8 |
--------------------------------------------------------------------------------
/README.md.orig:
--------------------------------------------------------------------------------
1 | ctci
2 | Solutions for "Cracking the Coding Interview v5"
3 |
4 | Due to copyrights , the questions themselves are not published
--------------------------------------------------------------------------------
/Swift/Chapter 1/Chapter 1.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Swift/Chapter 1/Chapter 1.playground/timeline.xctimeline:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Swift/Chapter 1/Question 6/README.md:
--------------------------------------------------------------------------------
1 | ## Question
2 | ```
3 | Given an image represented by an NxN matrix, where each pixel in the image is 4
4 | bytes, write a method to rotate the image by 90 degrees. Can you do this in place?
5 | ```
6 | ## Algorithm:
7 | ```
8 | 1) Get the transpose of the input
9 | 2) swap first and Nth column, second and N-1th column until u reach the N/2th column
10 | ```
--------------------------------------------------------------------------------
/Swift/Chapter 18/Question-1/Question.swift:
--------------------------------------------------------------------------------
1 |
2 | // Author: Prakash Natarajan (c) 2015
3 | // Email: nprakashece@gmail.com | pn33@buffalo.edu
4 | // License: GNU GPLv3
5 |
6 |
7 | import UIKit
8 |
9 | // 18.1
10 | /*
11 | Write a function that adds two numbers. You should not use + or any arithmetic op- erators.
12 | */
13 | /* algorithm:
14 | 1) calculate the sum part and carry part
15 | 2) add the parts individually
16 | */
17 |
18 | func sum(var a:Int, var b:Int) -> Int {
19 | var sum = 0;
20 | var carry = 0;
21 | while(b != 0) {
22 | sum = a ^ b;
23 | carry = (a & b) << 1;
24 | (a, b) = (sum, carry)
25 | }
26 | return a
27 | }
28 |
29 |
30 | //play ground samples
31 | sum(-1,1)
32 | sum(2,3)
--------------------------------------------------------------------------------
/Swift/Chapter 18/Question-1/README.md:
--------------------------------------------------------------------------------
1 | ## Question 18.1
2 | ```
3 | Write a function that adds two numbers. You should not use + or any arithmetic op- erators.
4 | ```
--------------------------------------------------------------------------------
/Swift/Chapter 2/Chapter 2.playground/contents.xcplayground:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Swift/Chapter 2/Chapter 2.playground/timeline.xctimeline:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-2/Question.swift:
--------------------------------------------------------------------------------
1 |
2 | // Author: Prakash Natarajan (c) 2014
3 | // Email: nprakashece@gmail.com | pn33@buffalo.edu
4 | // License: GNU GPLv3
5 |
6 | import UIKit
7 |
8 | class Question5_2 {
9 | func binary2(var num:Double) -> String {
10 | if(num <= 0 || num >= 1)
11 | { return "ERROR" }
12 | var binary:String = "."
13 | while (num > 0.0) {
14 | if(binary.utf16Count > 32) { return "ERROR" }
15 |
16 | var r = num * 2
17 | if(r >= 1) {
18 | binary += "1"
19 | num = r - 1
20 | }
21 | else {
22 | binary += "0"
23 | num = r
24 | }
25 | }
26 | return binary
27 | }
28 |
29 | }
30 |
31 | var pgm = Question5_2()
32 | pgm.binary2(0.125)
33 |
34 |
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-2/README.md:
--------------------------------------------------------------------------------
1 | ## Question 5_2
2 | ```
3 | Youaregiven two 32-bit numbers,N andM, andtwobitpositions, i andj. Write a method to insert Minto Nsuch that Mstarts at bit j and ends at bit i. Youcan assume that the bits j through i have enough space to fit all ofM. That is,ifM= 10011, you can assume that there are at least 5 bits between j and i. You would not, for example,havej-3 andi=2,becauseMcouldnotfully fitbetweenbit3andbit2.
4 |
5 | EXAMPLE:
6 | Input:N=16000000000, M=10011, i =2, j =6 Output: N = 10001001100
7 |
8 | ```
9 |
10 |
11 |
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-2/untitled:
--------------------------------------------------------------------------------
1 |
2 | // Author: Prakash Natarajan (c) 2014
3 | // Email: nprakashece@gmail.com | pn33@buffalo.edu
4 | // License: GNU GPLv3
5 |
6 | import UIKit
7 |
8 | class Question5_2 {
9 | func binary2(var num:Double) -> String {
10 | if(num <= 0 || num >= 1)
11 | { return "ERROR" }
12 | var binary:String = "."
13 | while (num > 0.0) {
14 | if(binary.utf16Count > 32) { return "ERROR" }
15 |
16 | var r = num * 2
17 | if(r >= 1) {
18 | binary += "1"
19 | num = r - 1
20 | }
21 | else {
22 | binary += "0"
23 | num = r
24 | }
25 | }
26 | return binary
27 | }
28 |
29 | }
30 |
31 | var pgm = Question5_2()
32 | pgm.binary2(0.125)
33 |
34 |
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-3/README.md:
--------------------------------------------------------------------------------
1 | ## Question 5_3
2 | ```
3 | Given a positive integer, print the next smallest and the next largest number that have the same number of 1 bits in their binary representation.
4 |
5 | ```
6 |
7 | ###Algorithm:
8 | Step by step illustration:
9 | ```
10 | 10011100
11 | 00011100 - right most string of 1's in x
12 | 00000011 - right shifted pattern except left most bit ------> [A]
13 | 00010000 - isolated left most bit of right most 1's pattern
14 | 00100000 - shiftleft-ed the isolated bit by one position ------> [B]
15 | 10000000 - left part of x, excluding right most 1's pattern ------> [C]
16 | 10100000 - add B and C (OR operation) ------> [D]
17 | 10100011 - add A and D which is required number 163
18 | ```
19 |
20 | ### Reference:
21 |
22 | [GeeksforGeeks c solution](http://www.geeksforgeeks.org/next-higher-number-with-same-number-of-set-bits/)
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-4/ReadMe.md:
--------------------------------------------------------------------------------
1 | ## ((n & (n-1)) == 0)
2 |
3 | ### Explanation:
4 | [Example code which is already Implemented](https://github.com/AlgorithmCrackers/Interview-Questions/blob/master/Bit-Hacks/NextPowerof2/NextPowerOf2.swift)
5 |
6 | ````
7 | Any power of 2 minus 1 is all ones: (2 N - 1 = 111....b)
8 |
9 | 2 = 2^1. 2-1 = 1 (1b)
10 | 4 = 2^2. 4-1 = 3 (11b)
11 | 8 = 2^3. 8-1 = 7 (111b)
12 | Take 8 for example. 1000 & 0111 = 0000
13 |
14 | So that expression tests if a number is NOT a power of 2.
15 |
16 | ````
17 |
18 | Reference:
19 | [Stack overflow](http://stackoverflow.com/questions/1053582/how-does-this-bitwise-operation-check-for-a-power-of-2)
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-5/Question.swift:
--------------------------------------------------------------------------------
1 | /*
2 | Write a function to determine the number of bits required to convert integer A to integer B
3 | Input: 31, 14 Output: 2
4 | */
5 |
6 | import Cocoa
7 | /*
8 | @param: a:Int Input first
9 | @param: b:Int Input Two
10 | @return Int Number of bit changes required
11 | */
12 |
13 | func bitsRequiredToConvertAtoB(a:Int, b:Int) -> Int { //O(number of resulting bits in a ^ b)
14 | return numberOf1(a ^ b)
15 | }
16 |
17 | /*
18 | @param: c:Int Input Number
19 | @return: returns the number of 1's present in the binary representation of the number
20 | */
21 | func numberOf1(var c:Int) -> Int { //O(number of bits in c)
22 | var count = 0
23 | while(c != 0) {
24 | if ((c & 1) == 1 ) {
25 | count++
26 | }
27 | c = c >> 1
28 | }
29 | return count
30 | }
31 |
32 | //tested in Playground
33 | //bitsRequiredToConvertAtoB(31, 30)
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-5/README.md:
--------------------------------------------------------------------------------
1 | ## Question 5_5
2 | ```
3 | Write a function to determine the number of bits required to convert integer A to integer B
4 | Input: 31, 14 Output: 2
5 |
6 | ```
7 |
8 | ###Algorithm:
9 | Step 1:
10 | ```
11 | XOR the two inputs and get the result
12 | ```
13 |
14 | Step 2:
15 | ```
16 | Count the number of 1's in the number. This is the result
17 | ```
18 |
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-6/Question.swift:
--------------------------------------------------------------------------------
1 |
2 |
3 | // Author: Prakash Natarajan (c) 2014
4 | // Email: nprakashece@gmail.com | pn33@buffalo.edu
5 | // License: GNU GPLv3
6 |
7 | import UIKit
8 |
9 | class Question5_6 {
10 | func swapOddEvenBits(var x:Int) -> Int {
11 | // 0x55555555 = 1431655765 for even place masking
12 | // 0xaaaaaaaa = 2863311530 for odd place masking
13 | return ( ((x & 2863311530) >> 1) | ((x & 1431655765) << 1) )
14 | }
15 | }
16 |
17 | var pgm = Question5_6()
18 | String(103217, radix:2)
19 | var res = pgm.swapOddEvenBits(103217)
20 | String(res, radix:2)
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/Swift/Chapter 5/Question-6/README.md:
--------------------------------------------------------------------------------
1 | ## Question 5_6
2 | ```
3 | Write a program to swap odd and even bits in an integer with as few instructions as possible (e.g., bit 0 and bit! are swapped, bit 2 and bit 3 are swapped, and soon)
4 |
5 | ```
6 |
7 |
8 |
--------------------------------------------------------------------------------
/Swift/README.md:
--------------------------------------------------------------------------------
1 | ## INTRODUCTION
2 | ------------
3 |
4 | Cracking the Coding Interview with Apple Swift.
5 | Buy the book and support the author. [Cracking the Coding Interview](http://www.amazon.com/dp/098478280X/)
6 |
7 | ## Respect the stack
8 | If you want to contribute, respect these rules :
9 | - One folder for each chapter called `Chapter X`.
10 | - Create One playground file calle `Chapter X`.
11 | - Implement each question under a `// MARK: `
12 | - Use extension for each question when this is possible
13 | - Implement a simple exemple below each question
14 |
15 | ## TODO
16 | ----
17 | - Chapter 2 - WIP
18 | - Chapter 3
19 | - Chapter 4
20 | - Chapter 6
21 | - Chapter 7
22 | - Chapter 8
23 | - Chapter 9
24 | - Chapter 10
25 | - Chapter 11
26 | - Chapter 12
27 | - Chapter 13
28 | - Chapter 14
29 | - Chapter 15
30 | - Chapter 16
31 | - Chapter 17
32 | - Chapter 18 - WIP
33 |
34 |
35 |
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_1/Question1_1.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_1_h__
2 | #define __Question_1_1_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question1_1
9 | {
10 | public:
11 | int run();
12 | bool isUniqueChars(const string& str);
13 | bool isUniqueChars2(const string& str);
14 | string result(bool value);
15 | };
16 |
17 | #endif // __Question_1_1_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_2/Question1_2.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include "Question1_2.h"
3 |
4 | using std::cout;
5 | using std::endl;
6 |
7 | void Question1_2::reverse(char* str)
8 | {
9 | char *ptrEnd = str;
10 | char temp;
11 |
12 | if (str)
13 | {
14 | while (*ptrEnd)
15 | {
16 | ptrEnd++;
17 | }
18 | ptrEnd--;
19 |
20 | while (str < ptrEnd)
21 | {
22 | temp = *str;
23 | *str++ = *ptrEnd;
24 | *ptrEnd-- = temp;
25 | }
26 | }
27 | }
28 |
29 | int Question1_2::run()
30 | {
31 | char input[][10] = { "abcde", "cat" };
32 |
33 | for (int i = 0; i < 2; i++)
34 | {
35 | cout << "reversing the string: " << input[i] << endl;
36 | reverse(input[i]);
37 | cout << "reverse of input string is " << input[i] << endl;
38 | }
39 |
40 | return 0;
41 | }
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_2/Question1_2.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_2_h__
2 | #define __Question_1_2_h__
3 |
4 | class Question1_2
5 | {
6 | public:
7 | int run();
8 | void reverse(char* str);
9 | };
10 |
11 | #endif // __Question_1_2_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_3/Question1_3.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_3_h__
2 | #define __Question_1_3_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question1_3
9 | {
10 | public:
11 | int run();
12 | bool permutation(const string& a, const string& b);
13 | string result(bool value);
14 | };
15 |
16 |
17 |
18 | #endif // __Question_1_3_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_3/Question1_3_B.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_3_B_h__
2 | #define __Question_1_3_B_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question1_3_B
9 | {
10 | public:
11 | int run();
12 | bool permutation(const string& a, const string& b);
13 | string result(bool value);
14 | };
15 |
16 |
17 |
18 | #endif // __Question_1_3_B_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_4/Question1_4.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_4_h__
2 | #define __Question_1_4_h__
3 | #include
4 |
5 | class Question1_4
6 | {
7 | public:
8 | int run();
9 | void replaceSpaces(std::unique_ptr&, int length);
10 | };
11 |
12 | #endif // __Question_1_4_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_5/Question1_5.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_5_h__
2 | #define __Question_1_5_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question1_5
9 | {
10 | public:
11 | int run();
12 | int stringToInt(const string& value);
13 | string intToString(int value);
14 | int countCompression(const string& str);
15 |
16 | /// C++ std::string is efficient and no need to use a "StringBuffer"-like structure.
17 | string compressBetter(const string& str);
18 | };
19 |
20 |
21 |
22 | #endif // __Question_1_5_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_6/Question1_6.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_6_h__
2 | #define __Question_1_6_h__
3 |
4 | class Question1_6
5 | {
6 | public:
7 | /**
8 | * Since we can't provide variable matrix size in C++, we will do it "the c way" and will provide a 1-dimensional
9 | * array
10 | */
11 | void rotate(int* matrix, int n);
12 | void printMatrix(int* matrix, int m, int n);
13 | int run();
14 | };
15 |
16 | #endif // __Question_1_6_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_7/Question1_7.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_7_h__
2 | #define __Question_1_7_h__
3 |
4 | class Question1_7
5 | {
6 | public:
7 | /**
8 | * Since we can't provide variable matrix size in C++, we will do it "the c way" and will provide a 1-dimensional
9 | * array
10 | */
11 | void setZeros(int* matrix, int m, int n);
12 | void printMatrix(int* matrix, int m, int n);
13 | int run();
14 | };
15 |
16 | #endif // __Question_1_7_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question1_8/Question1_8.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_1_8_h__
2 | #define __Question_1_8_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question1_8
9 | {
10 | public:
11 | string result(bool value);
12 | bool isRotation(const string& s1, const string& s2);
13 | int run();
14 | };
15 |
16 | #endif // __Question_1_8_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question2_1.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_2_1_h__
2 | #define __Question_2_1_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question2_1
9 | {
10 | public:
11 | int run();
12 | };
13 |
14 | #endif // __Question_2_1_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question2_2.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_2_2_h__
2 | #define __Question_2_2_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question2_2
9 | {
10 | public:
11 | int run();
12 | };
13 |
14 | #endif // __Question_2_2_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question2_3.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_2_3_h__
2 | #define __Question_2_3_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question2_3
9 | {
10 | public:
11 | int run();
12 | };
13 |
14 | #endif // __Question_2_3_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question2_4.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_2_4_h__
2 | #define __Question_2_4_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question2_4
9 | {
10 | public:
11 | int run();
12 | };
13 |
14 | #endif // __Question_2_4_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question2_5.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_2_5_h__
2 | #define __Question_2_5_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question2_5
9 | {
10 | public:
11 | int run();
12 | };
13 |
14 | #endif // __Question_2_5_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question2_6.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_2_6_h__
2 | #define __Question_2_6_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question2_6
9 | {
10 | public:
11 | int run();
12 | };
13 |
14 | #endif // __Question_2_6_h__
--------------------------------------------------------------------------------
/c++/Chapter 1/Question2_7.h:
--------------------------------------------------------------------------------
1 | #ifndef __Question_2_7_h__
2 | #define __Question_2_7_h__
3 |
4 | #include
5 |
6 | using std::string;
7 |
8 | class Question2_7
9 | {
10 | public:
11 | int run();
12 | };
13 |
14 | #endif // __Question_2_7_h__
--------------------------------------------------------------------------------
/c++/Chapter 11/Chapter11_1.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | using namespace std;
3 |
4 | void merge(int a[], int lastA, int b[], int lastB) {
5 | int index = lastB + lastA + 1;
6 | while(index >= 0) {
7 | if (a[lastA] > b[lastB]) {
8 | a[index] = a[lastA];
9 | lastA--;
10 | }
11 | else {
12 | a[index] = b[lastB];
13 | lastB--;
14 | }
15 | index--;
16 | }
17 | }
18 |
19 | int main(){
20 |
21 | int a[13] = {0, 4, 14, 23, 29, 30, 31};
22 | int b[] = {6, 7, 29, 31, 100, 200};
23 | merge(a, 6, b, 5);
24 | for (int i = 0; i < 13; ++i) {
25 | cout<
2 | #include "Chapter11.h"
3 | #include