├── 03_30_2104_epi ├── 166A.py ├── 3sum.py ├── 5_8.py ├── Elements of Programming interviews (new).pdf ├── Indeed_2014 ├── Indeed 2014 │ ├── .DS_Store │ ├── A-Collatz.html │ ├── A-Collatz_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── All_Scores.html │ ├── All_Scores_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ ├── tick.png │ │ └── timer.js │ ├── B-Binary_Tape.html │ ├── B-Binary_Tape_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── C-T_Shirts.html │ ├── C-T_Shirts_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── D-String_Manipulation.html │ ├── D-String_Manipulation_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── E-Elections.html │ ├── E-Elections_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── F-Pivot_The_Board.html │ ├── F-Pivot_The_Board_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── G-Gathering_Diamonds.html │ ├── G-Gathering_Diamonds_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── H-Slippery_Floor.html │ ├── H-Slippery_Floor_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── I-Tower_of_Coins.html │ ├── I-Tower_of_Coins_files │ │ ├── VIk2ags.png │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── J-Tea_Cups.html │ ├── J-Tea_Cups_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ └── timer.js │ ├── UT_Scores.html │ └── UT_Scores_files │ │ ├── bootstrap.css │ │ ├── bootstrap.js │ │ ├── custom.css │ │ ├── jquery.js │ │ ├── logo.png │ │ ├── tick.png │ │ └── timer.js └── __MACOSX │ └── Indeed 2014 │ ├── ._.DS_Store │ ├── ._All_Scores.html │ ├── ._C-T_Shirts.html │ ├── ._D-String_Manipulation.html │ ├── ._F-Pivot_The_Board.html │ ├── ._G-Gathering_Diamonds.html │ ├── ._H-Slippery_Floor.html │ ├── ._I-Tower_of_Coins.html │ ├── ._J-Tea_Cups.html │ ├── ._UT_Scores.html │ ├── A-Collatz_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── All_Scores_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ ├── ._tick.png │ └── ._timer.js │ ├── B-Binary_Tape_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── C-T_Shirts_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── D-String_Manipulation_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── E-Elections_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── F-Pivot_The_Board_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── G-Gathering_Diamonds_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── H-Slippery_Floor_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── I-Tower_of_Coins_files │ ├── ._VIk2ags.png │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ ├── J-Tea_Cups_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ └── ._timer.js │ └── UT_Scores_files │ ├── ._bootstrap.css │ ├── ._bootstrap.js │ ├── ._custom.css │ ├── ._jquery.js │ ├── ._logo.png │ ├── ._tick.png │ └── ._timer.js ├── LCA.py ├── LIS.py ├── Longest_unique_string.py ├── Queue2.py ├── SRM ├── 113e.py ├── 160A.py ├── 170C.py ├── 216B.py ├── 236B.py ├── 289B.py ├── 300B.py ├── 369C.py ├── 58A.py └── fox.py ├── allpaths.py ├── anagrams.py ├── balancedP.py ├── binarySearch.py ├── candies.py ├── convex_hull.py ├── diagnal.py ├── excludemultiply.py ├── greedy_knapsack.py ├── hack.py ├── intervals.py ├── inversions.py ├── kSmallest.py ├── kadane.py ├── kadane_gas.py ├── kthlargestFBghost.py ├── linearity_expectation.pdf ├── lines.py ├── longestConsecutive.py ├── max2dArray.py ├── maximumAbsurdity.py ├── median.py ├── mergeInterval.py ├── minPartition.py ├── moorevotung.py ├── n-way-merge.py ├── nextLargest.py ├── parentheses.py ├── parition.py ├── partition.py ├── permtedPalindrome.py ├── phonedigits.py ├── practice ├── .gitignore ├── .idea │ ├── .name │ ├── compiler.xml │ ├── copyright │ │ └── profiles_settings.xml │ ├── encodings.xml │ ├── libraries │ │ ├── SBT__org_scala_lang_modules_scala_xml_2_11_1_0_2_jar.xml │ │ ├── SBT__org_scala_lang_scala_library_2_11_7_jar.xml │ │ ├── SBT__org_scala_lang_scala_reflect_2_11_2_jar.xml │ │ └── SBT__org_scalatest_scalatest_2_11_2_2_4_jar.xml │ ├── misc.xml │ ├── modules.xml │ ├── modules │ │ ├── practice-build.iml │ │ └── practice.iml │ ├── sbt.xml │ ├── scala_compiler.xml │ ├── uiDesigner.xml │ └── workspace.xml ├── build.sbt ├── project │ ├── build.properties │ ├── plugins.sbt │ ├── project │ │ └── target │ │ │ └── config-classes │ │ │ ├── $6f8cb2b29e2f58deb1bb$$anonfun$$sbtdef$1.class │ │ │ ├── $6f8cb2b29e2f58deb1bb$.class │ │ │ ├── $6f8cb2b29e2f58deb1bb.cache │ │ │ └── $6f8cb2b29e2f58deb1bb.class │ └── target │ │ ├── config-classes │ │ ├── $10f573183ab7151be5c4$$anonfun$$sbtdef$1.class │ │ ├── $10f573183ab7151be5c4$.class │ │ ├── $10f573183ab7151be5c4.cache │ │ ├── $10f573183ab7151be5c4.class │ │ ├── $1df7c94e7644382b43f6$$anonfun$$sbtdef$1.class │ │ ├── $1df7c94e7644382b43f6$.class │ │ ├── $1df7c94e7644382b43f6.cache │ │ ├── $1df7c94e7644382b43f6.class │ │ ├── $219008663a9f28daaa1a$$anonfun$$sbtdef$1$$anonfun$apply$1.class │ │ ├── $219008663a9f28daaa1a$$anonfun$$sbtdef$1.class │ │ ├── $219008663a9f28daaa1a$.class │ │ ├── $219008663a9f28daaa1a.cache │ │ ├── $219008663a9f28daaa1a.class │ │ ├── $4269e82822ca8faab0c3$$anonfun$$sbtdef$1.class │ │ ├── $4269e82822ca8faab0c3$.class │ │ ├── $4269e82822ca8faab0c3.cache │ │ ├── $4269e82822ca8faab0c3.class │ │ ├── $4ee76c92a4080cfaa660$$anonfun$$sbtdef$1.class │ │ ├── $4ee76c92a4080cfaa660$.class │ │ ├── $4ee76c92a4080cfaa660.cache │ │ └── $4ee76c92a4080cfaa660.class │ │ ├── resolution-cache │ │ ├── default │ │ │ ├── interview-build │ │ │ │ └── scala_2.10 │ │ │ │ │ └── sbt_0.13 │ │ │ │ │ └── 0.1-SNAPSHOT │ │ │ │ │ ├── resolved.xml.properties │ │ │ │ │ └── resolved.xml.xml │ │ │ └── practice-build │ │ │ │ └── scala_2.10 │ │ │ │ └── sbt_0.13 │ │ │ │ └── 0.1-SNAPSHOT │ │ │ │ ├── resolved.xml.properties │ │ │ │ └── resolved.xml.xml │ │ └── reports │ │ │ ├── default-interview-build-compile-internal.xml │ │ │ ├── default-interview-build-compile.xml │ │ │ ├── default-interview-build-docs.xml │ │ │ ├── default-interview-build-optional.xml │ │ │ ├── default-interview-build-plugin.xml │ │ │ ├── default-interview-build-pom.xml │ │ │ ├── default-interview-build-provided.xml │ │ │ ├── default-interview-build-runtime-internal.xml │ │ │ ├── default-interview-build-runtime.xml │ │ │ ├── default-interview-build-scala-tool.xml │ │ │ ├── default-interview-build-sources.xml │ │ │ ├── default-interview-build-test-internal.xml │ │ │ ├── default-interview-build-test.xml │ │ │ ├── default-practice-build-compile-internal.xml │ │ │ ├── default-practice-build-compile.xml │ │ │ ├── default-practice-build-docs.xml │ │ │ ├── default-practice-build-optional.xml │ │ │ ├── default-practice-build-plugin.xml │ │ │ ├── default-practice-build-pom.xml │ │ │ ├── default-practice-build-provided.xml │ │ │ ├── default-practice-build-runtime-internal.xml │ │ │ ├── default-practice-build-runtime.xml │ │ │ ├── default-practice-build-scala-tool.xml │ │ │ ├── default-practice-build-sources.xml │ │ │ ├── default-practice-build-test-internal.xml │ │ │ ├── default-practice-build-test.xml │ │ │ ├── ivy-report.css │ │ │ └── ivy-report.xsl │ │ └── streams │ │ ├── $global │ │ ├── $global │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── out │ │ ├── dependencyPositions │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── update_cache_2.10 │ │ │ │ ├── input_dsp │ │ │ │ └── output_dsp │ │ ├── ivyConfiguration │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── out │ │ ├── ivySbt │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── out │ │ ├── projectDescriptors │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── out │ │ └── update │ │ │ └── $global │ │ │ └── streams │ │ │ ├── out │ │ │ └── update_cache_2.10 │ │ │ ├── inputs │ │ │ └── output │ │ ├── compile │ │ ├── $global │ │ │ └── $global │ │ │ │ └── discoveredMainClasses │ │ │ │ └── data │ │ ├── compile │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── out │ │ ├── compileIncremental │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ ├── export │ │ │ │ └── out │ │ ├── copyResources │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ ├── copy-resources │ │ │ │ └── out │ │ ├── dependencyClasspath │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── export │ │ ├── exportedProducts │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── export │ │ ├── externalDependencyClasspath │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── export │ │ ├── internalDependencyClasspath │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── export │ │ ├── managedClasspath │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── export │ │ ├── unmanagedClasspath │ │ │ └── $global │ │ │ │ └── streams │ │ │ │ └── export │ │ └── unmanagedJars │ │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ └── runtime │ │ ├── dependencyClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ ├── exportedProducts │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ ├── externalDependencyClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ ├── fullClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ ├── internalDependencyClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ ├── managedClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ ├── unmanagedClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ │ └── unmanagedJars │ │ └── $global │ │ └── streams │ │ └── export ├── src │ ├── main │ │ ├── java │ │ │ ├── Anagram.java │ │ │ ├── BinarySearch.java │ │ │ ├── Bits.java │ │ │ ├── Combinations.java │ │ │ ├── Combinations2.java │ │ │ ├── CountingSort.java │ │ │ ├── DNF.java │ │ │ ├── DeleteArray.java │ │ │ ├── DoublyLinkedList.java │ │ │ ├── DungeonGame.java │ │ │ ├── ExpressionEvaluator.java │ │ │ ├── FindDuplicate.java │ │ │ ├── HashTables.java │ │ │ ├── Interval.java │ │ │ ├── IntervalStuff.java │ │ │ ├── IpAddress.java │ │ │ ├── JustifyText.java │ │ │ ├── Knapsack1.java │ │ │ ├── LargestNumber.java │ │ │ ├── LineSweep.java │ │ │ ├── LongestIncreasingSubarray.java │ │ │ ├── Main.java │ │ │ ├── MaxDifference.java │ │ │ ├── MaxGap.java │ │ │ ├── MinWindowString.java │ │ │ ├── OneStreamingMedian.java │ │ │ ├── OperatorCombo.java │ │ │ ├── PatternWordMatch.java │ │ │ ├── PrefixCoveringSet.java │ │ │ ├── PrintSpiral.java │ │ │ ├── Realign.java │ │ │ ├── RegexMatch.java │ │ │ ├── RemoveParent.java │ │ │ ├── RotateArray.java │ │ │ ├── Searches.java │ │ │ ├── SlidingMax.java │ │ │ ├── StreamingMedian.java │ │ │ ├── Summary.java │ │ │ ├── Trie.java │ │ │ ├── Tuple.java │ │ │ ├── WalkArray.java │ │ │ ├── WordLadder.java │ │ │ └── codeforces │ │ │ │ ├── BinarySearch.java │ │ │ │ ├── GraphTraversal.java │ │ │ │ ├── MyScanner.java │ │ │ │ ├── P112A.java │ │ │ │ ├── P115A.java │ │ │ │ ├── P160A.java │ │ │ │ ├── P217A.java │ │ │ │ ├── P253B.java │ │ │ │ ├── P327A.java │ │ │ │ ├── P330B.java │ │ │ │ ├── P520B.java │ │ │ │ ├── P580A.java │ │ │ │ └── SubstringWithUniqe.java │ │ └── scala │ │ │ ├── Judge.scala │ │ │ ├── Solutions.scala │ │ │ └── Tree.scala │ └── test │ │ └── scala │ │ ├── AnagramTest.scala │ │ ├── ArrayWalkTest.scala │ │ ├── BinarySearchTest.scala │ │ ├── CombinationsTest.scala │ │ ├── CountingSortTest.scala │ │ ├── DNFTest.scala │ │ ├── DeleteArrayTest.scala │ │ ├── ExpressionEvaluator.scala │ │ ├── FindDuplicateTest.scala │ │ ├── HashTables.scala │ │ ├── IntervalTest.scala │ │ ├── InvalidParenTest.scala │ │ ├── IpAddressTest.scala │ │ ├── JustifyTextTest.scala │ │ ├── LongestIncreasingTest.scala │ │ ├── MaxDifferenceTest.scala │ │ ├── MaxGapTest.scala │ │ ├── MedianTest.scala │ │ ├── MinWindowStringtest.scala │ │ ├── OperatorComboTest.scala │ │ ├── P112ATest.scala │ │ ├── P160Test.scala │ │ ├── P327ATest.scala │ │ ├── P520Btest.scala │ │ ├── P580ATest.scala │ │ ├── RegexTest.scala │ │ ├── RotateArrayTest.scala │ │ ├── SearchesTest.scala │ │ ├── SubstringWithUniqeTest.scala │ │ └── TrieTest.scala └── target │ ├── .history │ ├── resolution-cache │ ├── interview │ │ ├── interview$sbt_2.11 │ │ │ └── 1.0 │ │ │ │ ├── resolved.xml.properties │ │ │ │ └── resolved.xml.xml │ │ ├── interview$sources_2.11 │ │ │ └── 1.0 │ │ │ │ ├── resolved.xml.properties │ │ │ │ └── resolved.xml.xml │ │ └── interview_2.11 │ │ │ └── 1.0 │ │ │ ├── resolved.xml.properties │ │ │ └── resolved.xml.xml │ └── reports │ │ ├── interview-interview$sbt_2.11-default.xml │ │ ├── interview-interview_2.11-compile-internal.xml │ │ ├── interview-interview_2.11-compile.xml │ │ ├── interview-interview_2.11-docs.xml │ │ ├── interview-interview_2.11-optional.xml │ │ ├── interview-interview_2.11-plugin.xml │ │ ├── interview-interview_2.11-pom.xml │ │ ├── interview-interview_2.11-provided.xml │ │ ├── interview-interview_2.11-runtime-internal.xml │ │ ├── interview-interview_2.11-runtime.xml │ │ ├── interview-interview_2.11-scala-tool.xml │ │ ├── interview-interview_2.11-sources.xml │ │ ├── interview-interview_2.11-test-internal.xml │ │ ├── interview-interview_2.11-test.xml │ │ ├── ivy-report.css │ │ └── ivy-report.xsl │ ├── scala-2.11 │ ├── classes │ │ ├── Bits.class │ │ ├── DNF.class │ │ ├── Interval.class │ │ ├── IntervalStuff.class │ │ ├── Judge$.class │ │ ├── Judge.class │ │ ├── Knapsack1.class │ │ ├── LargestNumber$1.class │ │ ├── LargestNumber.class │ │ ├── LineReader.class │ │ ├── LineSweep.class │ │ ├── Main.class │ │ ├── PatternWordMatch.class │ │ ├── PrefixCoveringSet.class │ │ ├── SlidingMax.class │ │ ├── Solution.class │ │ ├── Solutions$$anonfun$deDupeString$1.class │ │ ├── Solutions$$anonfun$deDupeString$2.class │ │ ├── Solutions$.class │ │ ├── Solutions.class │ │ ├── Summary.class │ │ ├── TreeNode$.class │ │ ├── TreeNode.class │ │ ├── TreeOperations.class │ │ ├── WordLadder.class │ │ └── codeforces │ │ │ ├── MyScanner.class │ │ │ ├── P112A.class │ │ │ ├── P160A.class │ │ │ ├── P253B.class │ │ │ ├── P327A.class │ │ │ └── P580A.class │ └── test-classes │ │ ├── Anagramtest$$anonfun$1.class │ │ ├── Anagramtest.class │ │ ├── IntervalTest$$anonfun$1.class │ │ ├── IntervalTest$$anonfun$2.class │ │ ├── IntervalTest$$anonfun$3.class │ │ ├── IntervalTest.class │ │ ├── InterviewTest$$anonfun$1.class │ │ ├── InterviewTest$$anonfun$randomArray$1.class │ │ ├── InterviewTest.class │ │ ├── P112ATest$$anonfun$1.class │ │ ├── P112ATest$$anonfun$2.class │ │ ├── P112ATest$$anonfun$3.class │ │ ├── P112ATest$$anonfun$4.class │ │ ├── P112ATest.class │ │ ├── P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$1.class │ │ ├── P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$2.class │ │ ├── P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$3.class │ │ ├── P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$4.class │ │ ├── P160ATest$$anonfun$1.class │ │ ├── P160ATest.class │ │ ├── P327ATest$$anonfun$1.class │ │ ├── P327ATest.class │ │ ├── P580ATest$$anonfun$1.class │ │ └── P580ATest.class │ └── streams │ ├── $global │ ├── $global │ │ └── $global │ │ │ └── streams │ │ │ └── out │ ├── dependencyPositions │ │ └── $global │ │ │ └── streams │ │ │ └── update_cache_2.11 │ │ │ ├── input_dsp │ │ │ └── output_dsp │ ├── ivyConfiguration │ │ └── $global │ │ │ └── streams │ │ │ └── out │ ├── ivySbt │ │ └── $global │ │ │ └── streams │ │ │ └── out │ ├── projectDescriptors │ │ └── $global │ │ │ └── streams │ │ │ └── out │ ├── update │ │ └── $global │ │ │ └── streams │ │ │ ├── out │ │ │ └── update_cache_2.11 │ │ │ ├── inputs │ │ │ └── output │ ├── updateClassifiers │ │ └── $global │ │ │ └── streams │ │ │ └── out │ └── updateSbtClassifiers │ │ └── $global │ │ └── streams │ │ └── out │ ├── compile │ ├── compile │ │ └── $global │ │ │ └── streams │ │ │ └── out │ ├── compileIncremental │ │ └── $global │ │ │ └── streams │ │ │ ├── export │ │ │ └── out │ ├── dependencyClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ ├── externalDependencyClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ ├── internalDependencyClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ ├── managedClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ ├── unmanagedClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ └── unmanagedJars │ │ └── $global │ │ └── streams │ │ └── export │ ├── runtime │ ├── externalDependencyClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ ├── managedClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ ├── unmanagedClasspath │ │ └── $global │ │ │ └── streams │ │ │ └── export │ └── unmanagedJars │ │ └── $global │ │ └── streams │ │ └── export │ └── test │ ├── externalDependencyClasspath │ └── $global │ │ └── streams │ │ └── export │ ├── managedClasspath │ └── $global │ │ └── streams │ │ └── export │ ├── unmanagedClasspath │ └── $global │ │ └── streams │ │ └── export │ └── unmanagedJars │ └── $global │ └── streams │ └── export ├── preOrderInrderbuild.py ├── random ├── random~ ├── reverseWords.py ├── right_pointer.py ├── rotate.py ├── someNeighbor.py ├── stack_Max.py ├── subsets.py ├── surround.py ├── twStackQ.py ├── uniquePaths2.py ├── uniquepaths (Case Conflict).py ├── uniquepaths.py ├── uva.py ├── validBST.py ├── vijayQ.py ├── vineetString.py ├── word_Ladder.py └── wordbreaking.py /03_30_2104_epi: -------------------------------------------------------------------------------- 1 | 1. Arrays and strings - 6.21 2 | 2. 6.22 phone number done 3 | 3. reverseWords in s atring correct 4 | 4. Run length enconding 5 | 5. Moore voting algorithm - IN the case of abc , moor'es agorithm will say c is maximum 6 | but a maximum does nto exist 7 | 6. Given two sorted arrays find the pair that sums to a pariuclar number 8 | -------------------------------------------------------------------------------- /166A.py: -------------------------------------------------------------------------------- 1 | import operator 2 | from operator import itemgetter 3 | from collections import defaultdict 4 | 5 | 6 | def mykey(x): 7 | return x[0],-x[1] 8 | 9 | n,k = map(lambda x:int(x), raw_input().split(" ")) 10 | 11 | 12 | l = [] 13 | for i in xrange(n): 14 | a,b = map(lambda x:int(x), raw_input().split(" ")) 15 | l.append((a,b)) 16 | 17 | l = sorted(l, key=mykey,reverse = True) 18 | 19 | #print l 20 | dic= defaultdict(int) 21 | 22 | for item in l: 23 | dic[item] += 1 24 | 25 | print dic[l[k-1]] 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /3sum.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # @return a list of lists of length 3, [[val1,val2,val3]] 3 | def threeSum(self, num): 4 | ans = [] 5 | num = sorted(num) 6 | 7 | prev = None 8 | for i in xrange(len(num)-1): 9 | if num[i] != prev: 10 | self.twosum(num[i+1:],-num[i],ans) 11 | prev = num[i] 12 | 13 | return ans 14 | 15 | def twosum(self,a,target,ans): 16 | i =0 17 | j = len(a) -1 18 | 19 | while i < j: 20 | if a[i] + a[j] == target: 21 | ans.append([target*-1,a[i],a[j]]) 22 | temp = a[i] 23 | while a[i] == temp and i < j: 24 | i += 1 25 | temp = a[j] 26 | while a[j] == temp and i < j: 27 | j -= 1 28 | 29 | elif a[i] + a[j] < target: 30 | temp = a[i] 31 | while a[i] == temp and i < j: 32 | i += 1 33 | 34 | elif a[i] + a[j] > target: 35 | temp = a[j] 36 | while a[j] == temp and i < j: 37 | j -= 1 38 | 39 | 40 | def main(): 41 | s = Solution() 42 | print s.threeSum([1,1,1,1,1,1,1,1,-1,-2,-2,-2]) 43 | print s.threeSum([0,0,0]) 44 | print s.threeSum([1,1,1]) 45 | print s.threeSum([1,-2,1]) 46 | print s.threeSum([-100,100,0,0,0,0,0,0]) 47 | print s.threeSum([-1,0,1,2,-1,-4]) 48 | 49 | if __name__ == '__main__': 50 | main() -------------------------------------------------------------------------------- /5_8.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def ssDecodeColIs(self,str_): 3 | val = 0 4 | for index,char in enumerate(str_): 5 | val = val + pow(26,index)*(ord(char) - 65 + 1) 6 | 7 | print val 8 | 9 | 10 | def main(): 11 | s = Solution() 12 | s.ssDecodeColIs('AAA') 13 | if __name__ == '__main__': 14 | main() -------------------------------------------------------------------------------- /Elements of Programming interviews (new).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Elements of Programming interviews (new).pdf -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/.DS_Store -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/A-Collatz_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/A-Collatz_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/All_Scores_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/All_Scores_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/All_Scores_files/tick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/All_Scores_files/tick.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/B-Binary_Tape_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/B-Binary_Tape_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/C-T_Shirts_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/C-T_Shirts_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/D-String_Manipulation_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/D-String_Manipulation_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/E-Elections_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/E-Elections_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/F-Pivot_The_Board_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/F-Pivot_The_Board_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/G-Gathering_Diamonds_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/G-Gathering_Diamonds_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/H-Slippery_Floor_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/H-Slippery_Floor_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/I-Tower_of_Coins_files/VIk2ags.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/I-Tower_of_Coins_files/VIk2ags.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/I-Tower_of_Coins_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/I-Tower_of_Coins_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/J-Tea_Cups_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/J-Tea_Cups_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/UT_Scores_files/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/UT_Scores_files/logo.png -------------------------------------------------------------------------------- /Indeed_2014/Indeed 2014/UT_Scores_files/tick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/Indeed 2014/UT_Scores_files/tick.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._.DS_Store: -------------------------------------------------------------------------------- 1 | Mac OS X  2 R -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._All_Scores.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._All_Scores.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._C-T_Shirts.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._C-T_Shirts.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._D-String_Manipulation.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._D-String_Manipulation.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._F-Pivot_The_Board.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._F-Pivot_The_Board.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._G-Gathering_Diamonds.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._G-Gathering_Diamonds.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._H-Slippery_Floor.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._H-Slippery_Floor.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._I-Tower_of_Coins.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._I-Tower_of_Coins.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._J-Tea_Cups.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._J-Tea_Cups.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/._UT_Scores.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/._UT_Scores.html -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/A-Collatz_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._tick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._tick.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/All_Scores_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/B-Binary_Tape_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/C-T_Shirts_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/D-String_Manipulation_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/E-Elections_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/F-Pivot_The_Board_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/G-Gathering_Diamonds_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/H-Slippery_Floor_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._VIk2ags.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._VIk2ags.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/I-Tower_of_Coins_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/J-Tea_Cups_files/._timer.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._bootstrap.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._bootstrap.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._bootstrap.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._bootstrap.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._custom.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._custom.css -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._jquery.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._jquery.js -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._logo.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._tick.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._tick.png -------------------------------------------------------------------------------- /Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._timer.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/Indeed_2014/__MACOSX/Indeed 2014/UT_Scores_files/._timer.js -------------------------------------------------------------------------------- /LIS.py: -------------------------------------------------------------------------------- 1 | # well I just know that I will need the length of the longest IS at that point 2 | 3 | def selection(a): 4 | pass 5 | def LIS(a): 6 | 7 | 8 | 9 | def main(): 10 | pass 11 | if __name__ == '__main__': 12 | main() -------------------------------------------------------------------------------- /Longest_unique_string.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | 3 | def lengthOfLongestSubstring(self, s): 4 | count =0 5 | max_len = 0 6 | start = 0 7 | cache = [-1]*256 8 | 9 | for index,ch in enumerate(s): 10 | char = ord(ch) 11 | if cache[char] == -1 or cache[char] < start: 12 | count += 1 13 | max_len = max(max_len,count) 14 | cache[char] = index 15 | else: 16 | start = cache[char] +1 17 | count = index- start +1 18 | max_len = max(max_len,count) 19 | cache[char] = index 20 | 21 | return max_len 22 | 23 | 24 | 25 | def main(): 26 | s = Solution() 27 | print s.lengthOfLongestSubstring("fpdcztbudxfipowpnamsrfgexjlbjrfoglthewbhtiriznzmolehqnlpwxrfowwwjrd") 28 | if __name__ == '__main__': 29 | main() -------------------------------------------------------------------------------- /Queue2.py: -------------------------------------------------------------------------------- 1 | # here we have queue with max 2 | # have a queue called deq that s going to hve the list of potential canddates 3 | # any number that that is greataer than its orevious will mother that nu,ber 4 | # Meagnin the dequeue shoud be descending order order 5 | # 6 | from collections import deque 7 | class Queue: 8 | 9 | def __init__(self): 10 | self.q = [] 11 | self.deq = deque() 12 | 13 | def push(self,item): 14 | self.q.insert(0, item) 15 | 16 | if len(self.deq) == 0: 17 | self.deq.append(item) 18 | else: 19 | 20 | while len(self.deq) > 0 and self.deq[-1] <= item : 21 | self.deq.pop() 22 | 23 | self.deq.append(item) 24 | 25 | 26 | 27 | 28 | 29 | def pop(self): 30 | item = self.q.pop() 31 | if item == self.deq[-1]: 32 | self.deq.popleft() 33 | 34 | return item 35 | 36 | 37 | def max(self): 38 | return self.deq[0] 39 | 40 | 41 | def __str__(self): 42 | return str(self.q) 43 | 44 | 45 | def main(): 46 | q = Queue() 47 | q.push(1) 48 | q.push(2) 49 | q.push(3) 50 | print q.pop() 51 | q.push(76) 52 | print q.max() 53 | print q 54 | q.push(176) 55 | print q.max() 56 | q.pop() 57 | print q.max() 58 | 59 | if __name__ == '__main__': 60 | main() -------------------------------------------------------------------------------- /SRM/113e.py: -------------------------------------------------------------------------------- 1 | # this is right. Atkeast now I know how to optimize 2 | 3 | 4 | n = 10000000 5 | 6 | nea = 0 7 | past = 1 8 | 9 | for i in range(2,n+1): 10 | ans = ((3*nea) + (past << 1)) % 1000000007 11 | nea = past 12 | past = ans 13 | 14 | print 3*nea % 1000000007 15 | 16 | -------------------------------------------------------------------------------- /SRM/160A.py: -------------------------------------------------------------------------------- 1 | n = int(raw_input()) 2 | coins = map(lambda x:int(x), raw_input().split(" ")) 3 | 4 | coins = sorted(coins,reverse=True) 5 | 6 | total_sum = sum(coins) 7 | sum_ = 0 8 | 9 | n = 0 10 | 11 | for coin in coins: 12 | sum_ += coin 13 | total_sum -= coin 14 | 15 | n += 1 16 | if sum_ > total_sum: 17 | break 18 | 19 | 20 | print n 21 | 22 | -------------------------------------------------------------------------------- /SRM/170C.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | import sys 3 | 4 | 5 | n,m = map(lambda x:int(x) , raw_input().split(" ")) 6 | adj_list = defaultdict(list) 7 | visited = [False]*(n+m+1) 8 | 9 | for i in range(1,m+1): 10 | adj_list[i] = [] 11 | 12 | def dfs(vertex): 13 | visited[vertex] = True 14 | 15 | for w in adj_list[vertex]: 16 | if visited[w] == False: 17 | dfs(w) 18 | 19 | 20 | k= 0 21 | 22 | for i in range(m+1,m+n+1): 23 | languages = map(lambda x:int(x) , raw_input().split(" ")) 24 | k += languages[0] 25 | 26 | for lang in languages[1:]: 27 | adj_list[i].append(lang) 28 | adj_list[lang].append(i) 29 | 30 | 31 | if k == 0: 32 | print n 33 | sys.exit() 34 | 35 | conn_comp = 0 36 | 37 | for node in xrange(1,n+m+1): 38 | if visited[node] == False: 39 | conn_comp += 1 40 | dfs(node) 41 | 42 | 43 | a = sum(map(lambda x: len(adj_list[x]) == 0, xrange(1,m+1))) 44 | 45 | print conn_comp - a - 1 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /SRM/216B.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | n,k,l,r,sall,sk = map(lambda x: int(x), "1000 700 782 1000 892330 648282".split(" ")) 4 | 5 | 6 | srem = sall - sk 7 | 8 | # so the sum of numbers from k to n-1 is srem 9 | # the min is l and the max is r 10 | out = [None]*n 11 | 12 | min_possible = srem/(n-k) + math.ceil(1.0*(srem%(n-k))/(n-k)) 13 | 14 | print min_possible 15 | 16 | for i in range(k,len(out)): 17 | out[i] = min_possible 18 | srem -= min_possible 19 | 20 | print srem 21 | 22 | if srem > 0: 23 | print out[n-1] 24 | 25 | out[n-1] += srem 26 | srem -= srem 27 | 28 | print sum(out[k:]), sall-sk 29 | 30 | min_possible = max(min(out[k:]),int(math.ceil(sk/k))) 31 | 32 | print min_possible 33 | 34 | 35 | for i in range(0,k): 36 | out[i] = min_possible 37 | sk -= min_possible 38 | 39 | 40 | print sk 41 | print srem 42 | 43 | print sum(out[0:k]) 44 | print sum(out) 45 | 46 | print out 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /SRM/236B.py: -------------------------------------------------------------------------------- 1 | def main(): 2 | n,k = map(lambda x:int(x), raw_input().split(" ")) 3 | a = map(lambda x:int(x), raw_input().split(" ")) 4 | count =0 5 | prev = None 6 | for i in range(len(a)): 7 | if prev == None: 8 | prev = a[i] 9 | else: 10 | if a[i] -prev != k: 11 | if a[i] - prev > 0: 12 | print '-',i+1, a[i] - prev - k 13 | a[i] = a[i] - (a[i] - prev - k) 14 | else: 15 | print '+',i+1, prev-a[i]+k 16 | a[i] = a[i] + prev-a[i]+k 17 | else: 18 | count += 1 19 | 20 | prev = a[i] 21 | 22 | if count == len(a)-1: 23 | print 0 24 | 25 | 26 | if __name__ == '__main__': 27 | main() -------------------------------------------------------------------------------- /SRM/289B.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # keepo track of the largest elements 4 | 5 | n,m,d = map(lambda x :int(x), raw_input().split(" ")) 6 | 7 | if n ==m and n == 1: 8 | print 0 9 | sys.exit() 10 | 11 | 12 | matrix = [] 13 | 14 | mod = None 15 | 16 | for i in range(n): 17 | row = map(lambda x:int(x), raw_input().split(" ")) 18 | 19 | for element in row: 20 | if mod == None: 21 | mod = element % d 22 | else: 23 | if element % d != mod: 24 | print "-1" 25 | sys.exit() 26 | break 27 | 28 | matrix.append(row) 29 | 30 | a=[item for row in matrix for item in row] 31 | 32 | a = sorted(a) 33 | 34 | median = a[n*m/2] 35 | 36 | print median 37 | 38 | ops = 0 39 | for element in a: 40 | ops += abs(element-median)/d 41 | 42 | 43 | print ops 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /SRM/300B.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | import sys 3 | 4 | 5 | def dfs(vertex): 6 | visited[vertex] = True 7 | vertices.append(vertex) 8 | 9 | for w in adj_list[vertex]: 10 | if visited[w] == False: 11 | dfs(w) 12 | 13 | 14 | n,m = map(lambda x:int(x), raw_input().split(" ")) 15 | 16 | adj_list = defaultdict(list) 17 | visited = [False]*(n+1) 18 | 19 | for index in range(m): 20 | start,end = map(lambda x:int(x), raw_input().split(" ")) 21 | adj_list[start].append(end) 22 | adj_list[end].append(start) 23 | 24 | conn_comp = 0 25 | 26 | twos = [] 27 | ones = [] 28 | threes = [] 29 | 30 | 31 | for node in range(1,n+1): 32 | if visited[node] == False: 33 | conn_comp += 1 34 | vertices = [] 35 | dfs(node) 36 | if len(vertices) > 3: 37 | print "-1" 38 | sys.exit() 39 | elif len(vertices) == 3: 40 | threes.append(vertices) 41 | # we have a super group 42 | elif len(vertices) == 1: 43 | ones.append(vertices[0]) 44 | elif len(vertices) == 2: 45 | twos.append(vertices) 46 | 47 | 48 | 49 | if len(ones) - len(twos) < 0 or (len(ones) - len(twos))%3 != 0: 50 | print "-1" 51 | 52 | else: 53 | for group in threes: 54 | print group[0],group[1],group[2] 55 | 56 | for i in range(len(twos)): 57 | print twos[i][0],twos[i][1],ones.pop() 58 | 59 | for i in xrange(0,len(ones),3): 60 | print " ".join(str(e) for e in ones[i:i+3]) 61 | 62 | 63 | -------------------------------------------------------------------------------- /SRM/369C.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | 4 | # the idea is to do dfs and on the backtrack get the set every ndoe to the count iof the problem roads that can be solved 5 | # from it 6 | 7 | n = int(raw_input()) 8 | 9 | adj_list ={} 10 | problem = set() 11 | visited = [False]*n 12 | problem_count = [0]*n 13 | 14 | 15 | for i in range(n-1): 16 | source, dest,label = map(lambda x:int(x), raw_input(" ").split()) 17 | adj_list[source].append(dest) 18 | adj_list[dest].append(source) 19 | problem.add((source,dest)) 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /SRM/58A.py: -------------------------------------------------------------------------------- 1 | word = raw_input() 2 | orig = "hello" 3 | 4 | a = [0]*len("hello") 5 | 6 | 7 | orig_index = 0 8 | word_index = 0 9 | 10 | while orig_index < len(orig) and word_index < len(word): 11 | if orig[orig_index] != word[word_index]: 12 | word_index += 1 13 | elif word[word_index] == orig[orig_index]: 14 | a[orig_index] = 1 15 | orig_index += 1 16 | word_index += 1 17 | 18 | 19 | if sum(a) == len(orig): 20 | print 'YES' 21 | else: 22 | print 'NO' 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /SRM/fox.py: -------------------------------------------------------------------------------- 1 | 2 | # in trees we dont need to use viisted at all cos anyway a node will be visited just once 3 | # then we know that in tree ishbud check that Im not exploring the parent again 4 | 5 | 6 | class FoxAndTouristFamilies: 7 | 8 | def dfs(self,city,parent,A,B,target,bridge_found): 9 | count = 0 10 | if bridge_found == True: 11 | count = 1 12 | 13 | for road in len(range(A)): 14 | neighbor = -1 15 | if(A[road] == city or B[road] == city): 16 | neighbor = B[road] if (A[road] == city) else A[road] 17 | 18 | bridge_found = (bridge_found or road == target) 19 | 20 | if neighbor != parent: 21 | count = count + dfs(neighbor,city,A,B,target,bridge_found) 22 | return count*1.0 23 | 24 | 25 | def expectedLength(self, A, B, f): 26 | # A contains the source city 27 | # B contains the destination city 28 | # f contrains the citry of family I 29 | # starting at every city node ,initiiate DFS 30 | city_cache=[] 31 | for road,city in enumerate(A): 32 | for fam,city in enumerate(family): 33 | count = dfs(city,-1,A,B,road,False) # thsi will return the number of nodes on the other side of the road 34 | prob_road = prob_road * (count/len(A)+1) 35 | length += prob_road 36 | 37 | return length 38 | 39 | -------------------------------------------------------------------------------- /allpaths.py: -------------------------------------------------------------------------------- 1 | class TreeNode: 2 | 3 | def __init__(self,val): 4 | self.left = None 5 | self.val = val 6 | self.right = None 7 | 8 | 9 | class Solution: 10 | def printAllPaths(self,root): 11 | self.printAllPathsHelper(root,[]) 12 | 13 | def printAllPathsHelper(self,root,out): 14 | if root.left == None and root.right == None: 15 | out.append(root.val) 16 | print out 17 | out.pop() 18 | else: 19 | out.append(root.val) 20 | if root.left != None: 21 | self.printAllPathsHelper(root.left, out) 22 | if root.right != None: 23 | self.printAllPathsHelper(root.right, out) 24 | out.pop() 25 | 26 | def main(): 27 | root = TreeNode(1) 28 | root.left = TreeNode(2) 29 | root.right = TreeNode(3) 30 | root.right.left = TreeNode(4) 31 | s = Solution() 32 | s.printAllPaths(root) 33 | 34 | if __name__ == '__main__': 35 | main() -------------------------------------------------------------------------------- /anagrams.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | class Solution: 4 | # @param strs, a list of strings 5 | # @return a list of strings 6 | def anagrams(self, strs): 7 | dic_ = defaultdict(list) 8 | 9 | for word in strs: 10 | repr_ = [0]*26 11 | for char in word: 12 | repr_[ord(char) - 97] += 1 13 | 14 | dic_[str(repr_)].append(word) 15 | 16 | ans = [] 17 | 18 | for key in dic_.keys(): 19 | if len(dic_[key]) > 1: 20 | for word in dic_[key]: 21 | ans.append(word) 22 | 23 | return ans 24 | 25 | #group set of anagrams 26 | def main(): 27 | s = Solution() 28 | print s.anagrams(['and','dna','dog','cat','act']) 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /binarySearch.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | def main(): 5 | pass 6 | 7 | if __name__ == '__main__': 8 | main() -------------------------------------------------------------------------------- /candies.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | def find_min(a): 4 | 5 | if len(a) == 1: 6 | return 1 7 | 8 | temp = [0]*len(a) 9 | temp[0] = 1 10 | prev = a[0] 11 | prev_val = 1 12 | 13 | for index in range(1,len(a)): 14 | if a[index] > prev: 15 | temp[index] = temp[index-1] + 1 16 | prev = a[index] 17 | prev_val = temp[index] 18 | else: 19 | prev_val = 1 20 | temp[index] = 1 21 | prev = a[index] 22 | 23 | prev_val = 1 24 | prev = a[len(a)-1] 25 | 26 | for index in reversed(range(0,len(a)-1)): 27 | if a[index] > prev: 28 | temp[index] = max(temp[index], prev_val+1) 29 | prev = a[index] 30 | prev_val = prev_val + 1 31 | else: 32 | prev_val = 1 33 | prev = a[index] 34 | 35 | print temp 36 | return sum(temp) 37 | 38 | def main(): 39 | a = [1,2,3,4,5,6,90] 40 | print find_min(a) 41 | 42 | a = [100,1,2,4,7,6,5,4,100] 43 | print find_min(a) 44 | 45 | a = [1,2,1,6,5,10,8,12] 46 | print find_min(a) 47 | 48 | a = [1,2] 49 | print find_min(a) 50 | 51 | 52 | if __name__ == '__main__': 53 | main() -------------------------------------------------------------------------------- /convex_hull.py: -------------------------------------------------------------------------------- 1 | def convex_hull(points): 2 | stack =[] 3 | sort(points) 4 | 5 | #lower part of the hul 6 | # is it is zero or anti clockwise I ca add else pop 7 | # so If I have clockweise I need to pop that pount 8 | lower=[] 9 | upper=[] 10 | for i in range(len(points)): 11 | 12 | while len(lower) >= 2 and cross_product(lower[-1], lower[-2]) <=0: 13 | lower.pop() 14 | 15 | lower.append(points[i]) 16 | 17 | for i in reverse(range(len(points))): 18 | 19 | while len(upper) >=3 and cross_product(upper[-1],upper[-2]) <=0: 20 | upper.pop() 21 | 22 | upper.append(points[i]) 23 | s 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /diagnal.py: -------------------------------------------------------------------------------- 1 | def f(a): 2 | for i in range(len(a)): 3 | l = i 4 | m = 0 5 | while True: 6 | if l >= 0 and m < len(a[0]): 7 | print a[l][m], 8 | l -= 1 9 | m += 1 10 | else: 11 | print 12 | break 13 | 14 | if len(a[0]) > 1: 15 | 16 | for i in range(1,len(a[0])): 17 | x = i 18 | y = len(a)-1 19 | 20 | while True: 21 | if x < len(a[0]) and y >=0: 22 | print a[y][x], 23 | x += 1 24 | y -= 1 25 | else: 26 | print 27 | break 28 | 29 | 30 | 31 | 32 | def main(): 33 | a = [[1,2,3], 34 | [4,5,6], 35 | [7,8,9], 36 | [10,11,12]] 37 | 38 | a = [[1,2,3], 39 | [4,5,6], 40 | [7,8,9], 41 | [10,11,12], 42 | [13,14,15]] 43 | f(a) 44 | 45 | if __name__ == '__main__': 46 | main() 47 | 48 | 49 | 50 | int left_max = 0; 51 | int left_min = 0; 52 | 53 | int right_max = 0; 54 | int right_min = 0; 55 | 56 | if(leftSubtree == null) { 57 | left_max = Integer.MIN_VALUE; 58 | left_min = Integer.MAX_VALUE; 59 | } 60 | else { 61 | left_max = leftSubtree.max; 62 | left_min = leftSubtree.min; 63 | } 64 | 65 | if(rightSubtree == null) { 66 | right_max = Integer.MIN_VALUE; 67 | right_min = Integer.MAX_VALUE; 68 | } 69 | else { 70 | right_max = rightSubtree.max; 71 | right_min = rightSubtree.min; 72 | } -------------------------------------------------------------------------------- /excludemultiply.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def multiply(self,a): 3 | fwd = [None]*len(a) 4 | bwd = [None]*len(a) 5 | 6 | mul =1 7 | fwd[0] = 1 8 | for i in range(len(a)-1): 9 | mul = mul*a[i] 10 | fwd[i+1] = mul 11 | 12 | bwd[-1] = 1 13 | mul =1 14 | for j in reversed(range(1,len(a))): 15 | mul = mul*a[j] 16 | bwd[j-1] = mul 17 | 18 | product = [] 19 | 20 | for i in range(len(fwd)): 21 | product.append(fwd[i] * bwd[i]) 22 | 23 | print fwd 24 | print bwd 25 | print product 26 | 27 | 28 | 29 | 30 | def main(): 31 | s = Solution() 32 | s.multiply([1,2,3,4,5]) 33 | if __name__ == '__main__': 34 | main() -------------------------------------------------------------------------------- /greedy_knapsack.py: -------------------------------------------------------------------------------- 1 | w=[] 2 | v=[] 3 | quad_list=[] 4 | max_weights=10 5 | 6 | for i in range(0,len(w)): 7 | ratio = v[i]/w[i] 8 | quad_list.append((i,v[i],w[i],ratio)) 9 | 10 | 11 | for k in range(1,11): 12 | for quad in quad_list: 13 | no_items = floor() 14 | 15 | -------------------------------------------------------------------------------- /hack.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | N = 10 4 | a = [1,1,5,4,3,6,6,5,9,10] 5 | 6 | map_ = defaultdict(set) 7 | 8 | for i in xrange(N-1): 9 | for j in xrange(i+1,N): 10 | if a[j] > a[i]: 11 | map_[a[i]].add(a[j]) 12 | 13 | 14 | print map_ 15 | count = 0 16 | 17 | 18 | for key in map_.keys(): 19 | greater = map_[key] 20 | for element in greater: 21 | print key,element,map_[element] 22 | count = count + len(map_[element]) 23 | 24 | print count -------------------------------------------------------------------------------- /inversions.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # return a number 3 | def inversions(self,a): 4 | 5 | if len(a) == 1: 6 | return (a,0) 7 | else: 8 | sub_ar1,inv1 = self.inversions(a[0:len(a)/2]) 9 | sub_ar2,inv2 = self.inversions(a[len(a)/2:]) 10 | (count,c) = self.merge(sub_ar1,sub_ar2) 11 | 12 | print sub_ar1,sub_ar2,c 13 | return (c,count+inv1+inv2) 14 | 15 | # return a merged array such that 16 | def merge(self,a,b): 17 | count = 0 18 | i = 0 19 | j = 0 20 | 21 | while i < len(a) and j < len(b): 22 | if a[i] > b[j]: 23 | count += len(a) - i 24 | j += 1 25 | elif a[i] <= b[j]: 26 | i += 1 27 | 28 | i = 0 29 | j = 0 30 | c = [] 31 | 32 | while i < len(a) or j < len(b): 33 | if i == len(a): 34 | c.append(b[j]) 35 | j += 1 36 | elif j == len(b): 37 | c.append(a[i]) 38 | i += 1 39 | elif a[i] < b[j]: 40 | c.append(a[i]) 41 | i += 1 42 | elif b[j] <= a[i]: 43 | c.append(b[j]) 44 | j += 1 45 | 46 | return (count,c) 47 | 48 | def main(): 49 | s = Solution() 50 | print s.inversions([10]) 51 | 52 | if __name__ == '__main__': 53 | main() -------------------------------------------------------------------------------- /kSmallest.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class Solution: 4 | def selection(self,a,k): 5 | 6 | 7 | 8 | 9 | def main(): 10 | s = Solution() 11 | s.selection(a, k) 12 | if __name__ == '__main__': 13 | main() 14 | -------------------------------------------------------------------------------- /kadane.py: -------------------------------------------------------------------------------- 1 | # Any positive number wil the following number unless it is a negatver 2 | # sum_so far will change only when the sum_so_far become negative 3 | # kdaane requires atleast one positive number 4 | # if there are only negative numbers then we nee4d 5 | def kadane(a): 6 | if len(a) == 0: 7 | return -1 8 | 9 | max_sum = a[0] 10 | max_here = a[0] 11 | start = 0 12 | end = 0 13 | 14 | # use sum_so_far as a peioxy 15 | i = 0 16 | 17 | while i < len(a): 18 | max_here += a[i] 19 | 20 | if max_here < 0: 21 | 22 | 23 | if sum_so_far >= max_sum: 24 | max_sum = sum_so_far 25 | end = i 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | pass -------------------------------------------------------------------------------- /kthlargestFBghost.py: -------------------------------------------------------------------------------- 1 | 2 | class Solution: 3 | 4 | def kthlargest(matrix,k): 5 | 6 | 7 | 8 | def main(): 9 | pass 10 | if __name__ == '__main__': 11 | main() -------------------------------------------------------------------------------- /linearity_expectation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/linearity_expectation.pdf -------------------------------------------------------------------------------- /longestConsecutive.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | def longestConsecutive(self,array): 3 | cache = {} 4 | 5 | for num in array: 6 | if num not in cache: 7 | num[cache] = 8 | -------------------------------------------------------------------------------- /max2dArray.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | 3 | def maxSum(self,m): 4 | pass 5 | 6 | 7 | 8 | def main(): 9 | pass 10 | if __name__ == '__main__': 11 | main() -------------------------------------------------------------------------------- /maximumAbsurdity.py: -------------------------------------------------------------------------------- 1 | n,k = map(lambda x:int(x), raw_input().split(" ")) 2 | a = map(lambda x:int(x), raw_input().split(" ")) 3 | 4 | 5 | # we need to compute the maximum of all sums which have lenth k. But only go till n-k positions. Since we 6 | # want some remaining for b. 7 | i = 0 8 | j = i + k 9 | sum_ = sum(a[i:j]) 10 | max_sum = sum_ 11 | max_a = 0 12 | 13 | while j < len(a) - k: 14 | sum_ = sum_ + a[j] 15 | 16 | if sum_ > max_sum: 17 | max_a = i 18 | max_sum = sum_ 19 | 20 | sum_ = sum_ - a[i] 21 | j += 1 22 | i += 1 23 | 24 | 25 | 26 | print i 27 | 28 | def max_sum_k(a,k): 29 | # takes an array and outputs the max_sum array of length k 30 | # with an index and the maximum sum 31 | # time taken is O(n) 32 | 33 | sum_ = sum(a[0:k]) 34 | max_sum = sum_ 35 | max_index = 0 36 | i = 1 37 | j = i+k 38 | 39 | 40 | while j < len(a)- k: 41 | sum_ = sum_ + a[j] 42 | 43 | if sum_ > max_sum: 44 | max_a = i 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /median.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/median.py -------------------------------------------------------------------------------- /mergeInterval.py: -------------------------------------------------------------------------------- 1 | class Interval: 2 | def __init__(self, s=0, e=0): 3 | self.start = s 4 | self.end = e 5 | 6 | class Solution: 7 | # @param intervals, a list of Intervals 8 | # @param newInterval, a Interval 9 | # @return a list of Interval 10 | def insert(self, intervals, newInterval): 11 | # find the smallest interval such that newInterval.start 12 | for interval in intervals: 13 | if newInterval.start < 14 | 15 | 16 | 17 | def binarySearchStart(): 18 | pass 19 | 20 | #find smallest interval such that interval.end <= newInterval 21 | def binarySearchEnd(intervals,newInterval): 22 | start = 0 23 | end = len(intervals) -1 24 | 25 | while( start < end): 26 | mid = (start + end)/2 27 | 28 | if intervals[mid].end < newInterval.start: 29 | end = mid+1 30 | 31 | elif intervals[mid].end >= intervals[mid].start: 32 | start = mid 33 | 34 | return hi 35 | 36 | 37 | 38 | 39 | 40 | def main(): 41 | s = Solution() 42 | print s.insert([Interval(1,3),Interval(6,9)],Interval(2,5)) 43 | 44 | if __name__ == '__main__': 45 | main() -------------------------------------------------------------------------------- /moorevotung.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/moorevotung.py -------------------------------------------------------------------------------- /n-way-merge.py: -------------------------------------------------------------------------------- 1 | import heapq 2 | from heapq import heappush 3 | 4 | class Solution: 5 | def n_way_merge(self,many): 6 | h = [] 7 | indices = [0]*len(many) 8 | out = [] 9 | 10 | while True: 11 | for i,array in enumerate(many): 12 | heappush(h,(array[indices[i]],i)) 13 | 14 | element = heapq.heappop(h) 15 | out.append(element[0]) 16 | indices[element[1]] += 1 17 | 18 | 19 | 20 | 21 | 22 | def main(): 23 | pass 24 | 25 | if __name__ == '__main__': 26 | main() -------------------------------------------------------------------------------- /nextLargest.py: -------------------------------------------------------------------------------- 1 | class TreeNode: 2 | def __init__(self, x): 3 | self.val = x 4 | self.left = None 5 | self.right = None 6 | 7 | class Solution: 8 | # @param root, a tree node 9 | # @return a boolean 10 | # for every subtree u have a >= and a less = 11 | # every node must be within this 12 | 13 | def nextLargest(self,root,val): 14 | if root.val == None: 15 | return -1 16 | elif root.val > val and root.left == None: 17 | return root.val 18 | else: 19 | if root.val > val: 20 | self.nextLargest(root.left,val) 21 | elif root.val <= val: 22 | self.nextLargest(root.right,val 23 | ) 24 | 25 | def main(): 26 | pass 27 | if __name__ == '__main__': 28 | main() -------------------------------------------------------------------------------- /parentheses.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # @param an integer 3 | # @return a list of string 4 | def generateParenthesis(self, n): 5 | self.generateParanthesesHelper("",0,n) 6 | 7 | def generateParanthesesHelper(self,str_,count,n): 8 | if count == 0 and len(str_) == n*2: 9 | print str_ 10 | 11 | elif count < 0 or len(str_) > n*2: 12 | return 13 | else: 14 | self.generateParanthesesHelper(str_+"(",count+1,n) 15 | self.generateParanthesesHelper(str_+")",count-1,n) 16 | 17 | 18 | 19 | 20 | 21 | 22 | def main(): 23 | s = Solution() 24 | s.generateParenthesis(1) 25 | 26 | 27 | if __name__ == '__main__': 28 | main() 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /parition.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # @param s, a string 3 | # @return a list of lists of string 4 | ans = [] 5 | local_ans = [] 6 | def partitionHelper(self, s): 7 | if s == "": 8 | copy = [x for x in Solution.local_ans] 9 | Solution.ans.append(copy) 10 | return 11 | else: 12 | for i in xrange(1,len(s)+1): 13 | if self.check(s[0:i]) == False: 14 | continue 15 | else: 16 | Solution.local_ans.append(s[0:i]) 17 | self.partitionHelper(s[i:]) 18 | Solution.local_ans.pop() 19 | return 20 | 21 | 22 | def partition(self,s): 23 | ans = [] 24 | local_ans = [] 25 | self.partitionHelper(s) 26 | return Solution.ans 27 | 28 | def check(self,a): 29 | i = 0 30 | j = len(a) - 1 31 | 32 | while i < j : 33 | if a[i] != a[j]: 34 | return False 35 | else: 36 | i += 1 37 | j -= 1 38 | 39 | return True 40 | 41 | 42 | def main(): 43 | s = Solution() 44 | print s.partition("aabaaaaaaa") 45 | 46 | if __name__ == '__main__': 47 | main() -------------------------------------------------------------------------------- /partition.py: -------------------------------------------------------------------------------- 1 | # Definition for singly-linked list. 2 | class ListNode: 3 | def __init__(self, x): 4 | self.val = x 5 | self.next = None 6 | 7 | def __str__(self): 8 | return str(self.val) 9 | 10 | class Solution: 11 | # @param head, a ListNode 12 | # @param x, an integer 13 | # @return a ListNode 14 | def partition(self, head, x): 15 | less = [] 16 | more_than = [] 17 | print 'OW' 18 | while head != None: 19 | #print head 20 | #print head.val 21 | if head.val < x: 22 | less.append(head) 23 | else: 24 | more_than.append(head) 25 | 26 | head = head.next 27 | 28 | print 'here1' 29 | while len(more_than) > 0: 30 | node = more_than.pop() 31 | node.next = None 32 | head = self.insert_begin(head,node) 33 | 34 | print 'here2' 35 | 36 | while len(less) > 0: 37 | node = less.pop() 38 | node.next = None 39 | head = self.insert_begin(head,node) 40 | 41 | print 'here3' 42 | 43 | return head 44 | 45 | def insert_begin(self,head,node): 46 | if head == None: 47 | head = node 48 | else: 49 | node.next = head 50 | head = node 51 | 52 | print head 53 | return head 54 | 55 | 56 | def main(): 57 | s = Solution() 58 | 59 | head = ListNode(2) 60 | head.next = ListNode(1) 61 | #head.next.next = ListNode(50) 62 | 63 | print s.partition(head, 2) 64 | 65 | while head != None: 66 | print head.val 67 | head = head.next 68 | if __name__ == '__main__': 69 | main() 70 | -------------------------------------------------------------------------------- /permtedPalindrome.py: -------------------------------------------------------------------------------- 1 | from collections import defaultdict 2 | 3 | class Solution: 4 | def isPalndrome(self,str_): 5 | dic = defaultdict(int) 6 | 7 | for char in str_: 8 | dic[char] += 1 9 | 10 | odd_count = 0 11 | for count in dic.values(): 12 | if odd_count > 1: 13 | return False 14 | 15 | if count % 2 != 0: 16 | odd_count += 1 17 | 18 | return True 19 | 20 | 21 | def main(): 22 | s = Solution() 23 | print s.isPalndrome("f") 24 | print s.isPalndrome("f") 25 | print s.isPalndrome("f") 26 | 27 | 28 | if __name__ == '__main__': 29 | main() -------------------------------------------------------------------------------- /phonedigits.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | 3 | table = [] 4 | result = [] 5 | def __init__(self): 6 | Solution.table.append("") 7 | Solution.table.append("@") 8 | Solution.table.append("abc") 9 | Solution.table.append("def") 10 | Solution.table.append("ghi") 11 | Solution.table.append("jkl") 12 | Solution.table.append("mno") 13 | Solution.table.append("pqrs") 14 | Solution.table.append("tuv") 15 | Solution.table.append("wxyz") 16 | 17 | def letterCombinations(self, digits): 18 | self.letterCombinationsH(digits, []) 19 | ans = Solution.result 20 | Solution.result = [] 21 | Solution.table = [] 22 | return ans 23 | 24 | def letterCombinationsH(self,digits,result): 25 | 26 | if digits == "": 27 | if result != "": 28 | Solution.result.append("".join(result)) 29 | else: 30 | for char in Solution.table[int(digits[0])]: 31 | result.append(char) 32 | self.letterCombinationsH(digits[1:], result) 33 | result.pop() 34 | 35 | 36 | def main(): 37 | s = Solution() 38 | print s.letterCombinations("234") 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /practice/.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .settings/ 4 | target/ 5 | -------------------------------------------------------------------------------- /practice/.idea/.name: -------------------------------------------------------------------------------- 1 | Interview -------------------------------------------------------------------------------- /practice/.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /practice/.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /practice/.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /practice/.idea/libraries/SBT__org_scala_lang_modules_scala_xml_2_11_1_0_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /practice/.idea/libraries/SBT__org_scala_lang_scala_library_2_11_7_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /practice/.idea/libraries/SBT__org_scala_lang_scala_reflect_2_11_2_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /practice/.idea/libraries/SBT__org_scalatest_scalatest_2_11_2_2_4_jar.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /practice/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1.8 31 | 32 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /practice/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /practice/.idea/sbt.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 26 | 27 | -------------------------------------------------------------------------------- /practice/.idea/scala_compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /practice/build.sbt: -------------------------------------------------------------------------------- 1 | name := "Interview" 2 | 3 | version := "1.0" 4 | 5 | scalaVersion := "2.11.7" 6 | 7 | libraryDependencies += "org.scalatest" % "scalatest_2.11" % "2.2.4" % "test" 8 | -------------------------------------------------------------------------------- /practice/project/build.properties: -------------------------------------------------------------------------------- 1 | sbt.version = 0.13.8 -------------------------------------------------------------------------------- /practice/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | logLevel := Level.Warn -------------------------------------------------------------------------------- /practice/project/project/target/config-classes/$6f8cb2b29e2f58deb1bb$$anonfun$$sbtdef$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/project/target/config-classes/$6f8cb2b29e2f58deb1bb$$anonfun$$sbtdef$1.class -------------------------------------------------------------------------------- /practice/project/project/target/config-classes/$6f8cb2b29e2f58deb1bb$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/project/target/config-classes/$6f8cb2b29e2f58deb1bb$.class -------------------------------------------------------------------------------- /practice/project/project/target/config-classes/$6f8cb2b29e2f58deb1bb.cache: -------------------------------------------------------------------------------- 1 | sbt.internals.DslEntry -------------------------------------------------------------------------------- /practice/project/project/target/config-classes/$6f8cb2b29e2f58deb1bb.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/project/target/config-classes/$6f8cb2b29e2f58deb1bb.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$10f573183ab7151be5c4$$anonfun$$sbtdef$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$10f573183ab7151be5c4$$anonfun$$sbtdef$1.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$10f573183ab7151be5c4$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$10f573183ab7151be5c4$.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$10f573183ab7151be5c4.cache: -------------------------------------------------------------------------------- 1 | sbt.internals.DslEntry -------------------------------------------------------------------------------- /practice/project/target/config-classes/$10f573183ab7151be5c4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$10f573183ab7151be5c4.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$1df7c94e7644382b43f6$$anonfun$$sbtdef$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$1df7c94e7644382b43f6$$anonfun$$sbtdef$1.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$1df7c94e7644382b43f6$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$1df7c94e7644382b43f6$.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$1df7c94e7644382b43f6.cache: -------------------------------------------------------------------------------- 1 | sbt.internals.DslEntry -------------------------------------------------------------------------------- /practice/project/target/config-classes/$1df7c94e7644382b43f6.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$1df7c94e7644382b43f6.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$219008663a9f28daaa1a$$anonfun$$sbtdef$1$$anonfun$apply$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$219008663a9f28daaa1a$$anonfun$$sbtdef$1$$anonfun$apply$1.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$219008663a9f28daaa1a$$anonfun$$sbtdef$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$219008663a9f28daaa1a$$anonfun$$sbtdef$1.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$219008663a9f28daaa1a$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$219008663a9f28daaa1a$.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$219008663a9f28daaa1a.cache: -------------------------------------------------------------------------------- 1 | sbt.internals.DslEntry -------------------------------------------------------------------------------- /practice/project/target/config-classes/$219008663a9f28daaa1a.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$219008663a9f28daaa1a.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4269e82822ca8faab0c3$$anonfun$$sbtdef$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$4269e82822ca8faab0c3$$anonfun$$sbtdef$1.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4269e82822ca8faab0c3$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$4269e82822ca8faab0c3$.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4269e82822ca8faab0c3.cache: -------------------------------------------------------------------------------- 1 | sbt.internals.DslEntry -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4269e82822ca8faab0c3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$4269e82822ca8faab0c3.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4ee76c92a4080cfaa660$$anonfun$$sbtdef$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$4ee76c92a4080cfaa660$$anonfun$$sbtdef$1.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4ee76c92a4080cfaa660$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$4ee76c92a4080cfaa660$.class -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4ee76c92a4080cfaa660.cache: -------------------------------------------------------------------------------- 1 | sbt.internals.DslEntry -------------------------------------------------------------------------------- /practice/project/target/config-classes/$4ee76c92a4080cfaa660.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/config-classes/$4ee76c92a4080cfaa660.class -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/default/interview-build/scala_2.10/sbt_0.13/0.1-SNAPSHOT/resolved.xml.properties: -------------------------------------------------------------------------------- 1 | #default#interview-build;0.1-SNAPSHOT resolved revisions 2 | #Sun Jul 19 12:54:34 PDT 2015 3 | +organisation\:\#@\#\:+org.scala-lang\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+scala-compiler\:\#@\#\:+revision\:\#@\#\:+2.10.4\:\#@\#\:=2.10.4 release 2.10.4 null 4 | +organisation\:\#@\#\:+org.scala-lang\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+scala-library\:\#@\#\:+revision\:\#@\#\:+2.10.4\:\#@\#\:=2.10.4 ? 2.10.4 null 5 | +organisation\:\#@\#\:+org.scala-sbt\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+sbt\:\#@\#\:+revision\:\#@\#\:+0.13.8\:\#@\#\:=0.13.8 release 0.13.8 null 6 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/default/practice-build/scala_2.10/sbt_0.13/0.1-SNAPSHOT/resolved.xml.properties: -------------------------------------------------------------------------------- 1 | #default#practice-build;0.1-SNAPSHOT resolved revisions 2 | #Sun Feb 07 23:49:54 PST 2016 3 | +organisation\:\#@\#\:+org.scala-lang\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+scala-compiler\:\#@\#\:+revision\:\#@\#\:+2.10.4\:\#@\#\:=2.10.4 release 2.10.4 null 4 | +organisation\:\#@\#\:+org.scala-lang\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+scala-library\:\#@\#\:+revision\:\#@\#\:+2.10.4\:\#@\#\:=2.10.4 ? 2.10.4 null 5 | +organisation\:\#@\#\:+org.scala-sbt\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+sbt\:\#@\#\:+revision\:\#@\#\:+0.13.8\:\#@\#\:=0.13.8 release 0.13.8 null 6 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-compile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-docs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-optional.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-runtime-internal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-runtime.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-sources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-interview-build-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-compile.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-docs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-optional.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-runtime-internal.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-runtime.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-sources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/resolution-cache/reports/default-practice-build-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /practice/project/target/streams/$global/$global/$global/streams/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/$global/$global/$global/streams/out -------------------------------------------------------------------------------- /practice/project/target/streams/$global/dependencyPositions/$global/streams/update_cache_2.10/input_dsp: -------------------------------------------------------------------------------- 1 | org.scala-lang scala-library2.10.4provided -------------------------------------------------------------------------------- /practice/project/target/streams/$global/dependencyPositions/$global/streams/update_cache_2.10/output_dsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/$global/dependencyPositions/$global/streams/update_cache_2.10/output_dsp -------------------------------------------------------------------------------- /practice/project/target/streams/$global/ivyConfiguration/$global/streams/out: -------------------------------------------------------------------------------- 1 | [debug] Other repositories: 2 | [debug] Default repositories: 3 | [debug] Using inline dependencies specified in Scala. 4 | -------------------------------------------------------------------------------- /practice/project/target/streams/$global/ivySbt/$global/streams/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/$global/ivySbt/$global/streams/out -------------------------------------------------------------------------------- /practice/project/target/streams/$global/projectDescriptors/$global/streams/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/$global/projectDescriptors/$global/streams/out -------------------------------------------------------------------------------- /practice/project/target/streams/$global/update/$global/streams/update_cache_2.10/inputs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/$global/update/$global/streams/update_cache_2.10/inputs -------------------------------------------------------------------------------- /practice/project/target/streams/$global/update/$global/streams/update_cache_2.10/output: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/$global/update/$global/streams/update_cache_2.10/output -------------------------------------------------------------------------------- /practice/project/target/streams/compile/$global/$global/discoveredMainClasses/data: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /practice/project/target/streams/compile/compile/$global/streams/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/compile/compile/$global/streams/out -------------------------------------------------------------------------------- /practice/project/target/streams/compile/compileIncremental/$global/streams/export: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/compile/compileIncremental/$global/streams/export -------------------------------------------------------------------------------- /practice/project/target/streams/compile/compileIncremental/$global/streams/out: -------------------------------------------------------------------------------- 1 | [debug] 2 | [debug] Initial source changes: 3 | [debug] removed:Set() 4 | [debug] added: Set() 5 | [debug] modified: Set() 6 | [debug] Removed products: Set() 7 | [debug] External API changes: API Changes: Set() 8 | [debug] Modified binary dependencies: Set() 9 | [debug] Initial directly invalidated sources: Set() 10 | [debug] 11 | [debug] Sources indirectly invalidated by: 12 | [debug] product: Set() 13 | [debug] binary dep: Set() 14 | [debug] external source: Set() 15 | [debug] All initially invalidated sources: Set() 16 | -------------------------------------------------------------------------------- /practice/project/target/streams/compile/copyResources/$global/streams/copy-resources: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/project/target/streams/compile/copyResources/$global/streams/copy-resources -------------------------------------------------------------------------------- /practice/project/target/streams/compile/copyResources/$global/streams/out: -------------------------------------------------------------------------------- 1 | [debug] Copy resource mappings: 2 | [debug] 3 | -------------------------------------------------------------------------------- /practice/project/target/streams/compile/exportedProducts/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/Development/algo/practice/project/target/scala-2.10/sbt-0.13/classes 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/compile/internalDependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/compile/unmanagedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/compile/unmanagedJars/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/dependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/Development/algo/practice/project/target/scala-2.10/sbt-0.13/classes 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/exportedProducts/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/Development/algo/practice/project/target/scala-2.10/sbt-0.13/classes 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/externalDependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/fullClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/Development/algo/practice/project/target/scala-2.10/sbt-0.13/classes 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/internalDependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/Development/algo/practice/project/target/scala-2.10/sbt-0.13/classes 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/managedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/unmanagedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/project/target/streams/runtime/unmanagedJars/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/src/main/java/Anagram.java: -------------------------------------------------------------------------------- 1 | ///** 2 | // * Created by karthik on 8/9/15. 3 | // */ 4 | //public class Anagram { 5 | // public boolean isAnagram(String s, String t) { 6 | // if(s.length() != t.length()) { 7 | // return false; 8 | // } else { 9 | // int[] charMap = new int[26]; 10 | // 11 | // for(int i=0;i=0;i--) { 28 | // ans = ans + (int)Math.pow(26, s.length()-1 - 1)*mapString(s.charAt(i)); 29 | // } 30 | // 31 | // } 32 | // 33 | // 34 | //} 35 | -------------------------------------------------------------------------------- /practice/src/main/java/BinarySearch.java: -------------------------------------------------------------------------------- 1 | ///** 2 | // * Created by karthik on 2/22/16. 3 | // */ 4 | //public class BinarySearch { 5 | // // The most importnt thing in binary saearch 6 | // 7 | // public int binarySearch(int []a, int target) { 8 | // int lo = 0; 9 | // int hi = a.length -1 ; 10 | // 11 | // while(lo <= hi) { 12 | // 13 | // } 14 | // } 15 | //} 16 | -------------------------------------------------------------------------------- /practice/src/main/java/Combinations.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | /** 5 | * Created by karthik on 2/28/16. 6 | */ 7 | public class Combinations { 8 | List> solution = new ArrayList<>(); 9 | public List> combine(int n, int k) { 10 | solution.clear(); 11 | for(int i=1;i<=n;i++) { 12 | helper(i, k, new ArrayList<>(), n); 13 | } 14 | return solution; 15 | } 16 | 17 | public void helper(int startFrom, int remainingSpots, List current, int n) { 18 | if(remainingSpots == 1) { 19 | List ans = new ArrayList<>(); 20 | current.add(startFrom); 21 | ans.addAll(current); 22 | current.remove(current.size()-1); 23 | solution.add(ans); 24 | return; 25 | } else { 26 | current.add(startFrom); 27 | for(int i =startFrom+1;i<=n;i++) { 28 | helper(i, remainingSpots -1, current, n); 29 | } 30 | current.remove(current.size()-1); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /practice/src/main/java/CountingSort.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | import java.util.Map; 3 | import java.util.TreeMap; 4 | 5 | /** 6 | * Created by karthik on 1/10/16. 7 | */ 8 | public class CountingSort { 9 | public static void sort(int [] a) { 10 | TreeMap map = new TreeMap<>(); 11 | 12 | for(int i=-0; i entry: map.entrySet()) { 23 | Integer key = entry.getKey(); 24 | Integer count = entry.getValue(); 25 | 26 | while (count-- > 0) { 27 | a[arrayIndex] = key; 28 | arrayIndex++; 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /practice/src/main/java/DNF.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 7/19/15. 3 | */ 4 | public class DNF { 5 | public int[] dutchNationalFlag(int[] a) { 6 | int zeroPointer = 0; 7 | int twoPointer = a.length -1; 8 | int i = 0; 9 | 10 | while(i <= twoPointer) { 11 | if(a[i] == 0 && a[zeroPointer] == 0) { 12 | i++; 13 | zeroPointer++; 14 | } else if(a[i] == 1) { 15 | i++; 16 | } else if(a[i] == 0) { 17 | swap(i, zeroPointer, a); 18 | zeroPointer++; 19 | } else { 20 | swap(i, twoPointer, a); 21 | twoPointer--; 22 | } 23 | } 24 | return a; 25 | } 26 | 27 | private void swap(int i, int j, int[] a) { 28 | int temp = a[i]; 29 | a[i] = a[j]; 30 | a[j] = temp; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /practice/src/main/java/DungeonGame.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 3/5/16. 3 | */ 4 | public class DungeonGame { 5 | public int calculateMinimumHP(int[][] dungeon) { 6 | int cache[][] = new int[dungeon.length][dungeon[0].length]; 7 | int[][] successor = new int[][]{{0, 1}, {1, 0}}; 8 | 9 | for(int i=dungeon.length;i>=0;i--) { 10 | for(int j=dungeon[0].length;j>=0;j--) { 11 | int max_neighbor = 1; 12 | for(int k=0;k=0 && x_delta < dungeon[0].length && y_delta >=0 && y_delta < dungeon.length) { 17 | max_neighbor = Math.min(cache[y_delta][x_delta], max_neighbor); 18 | } 19 | } 20 | 21 | if(dungeon[i][j] >= 0) { 22 | cache[i][j] = 1; 23 | } else { 24 | cache[i][j] = max_neighbor + -(dungeon[i][j]); 25 | } 26 | } 27 | } 28 | return cache[0][0]; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /practice/src/main/java/FindDuplicate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 3/20/16. 3 | */ 4 | public class FindDuplicate { 5 | public static int solution(int [] a) { 6 | // where a represents in array with the duplicate element 7 | 8 | // what I am going to do is split the range (1...n) and find the element in the ra 9 | // range that is the duplicate 10 | 11 | int lo = 1; 12 | int hi = a.length-1; 13 | 14 | if(a.length == 1) { 15 | return 1; 16 | } 17 | 18 | 19 | while(lo < hi) { 20 | int mid = lo + (hi - lo)/2; // round down 21 | 22 | int uniqueItemsinLow = mid - lo +1; 23 | 24 | int itemsOfArray = 0; 25 | for(int item: a) { 26 | if(item >= lo && item <=mid) { 27 | itemsOfArray++; 28 | } 29 | } 30 | 31 | if(itemsOfArray > uniqueItemsinLow) { 32 | hi = mid; 33 | } else { 34 | lo = mid + 1; 35 | } 36 | } 37 | 38 | return lo; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /practice/src/main/java/Interval.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 1/9/16. 3 | */ 4 | public class Interval { 5 | int start; 6 | int end; 7 | 8 | public Interval(int start, int end) { 9 | this.start = start; 10 | this.end = end; 11 | } 12 | 13 | public int size = end - start +1 ; 14 | 15 | public void setEnd(int a) { 16 | this.end = a; 17 | } 18 | 19 | public void setStart(int a) { 20 | this.start = a; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /practice/src/main/java/IntervalStuff.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 1/9/16. 3 | */ 4 | public class IntervalStuff { 5 | public static boolean isIntersect(Interval a, Interval b) { 6 | if(b.start >= a.end || a.start >= b.end) { 7 | return false; 8 | } else { 9 | return true; 10 | } 11 | } 12 | 13 | public static Interval intersect(Interval a, Interval b) { 14 | if(!isIntersect(a, b)) { 15 | return null; 16 | } else { 17 | return new Interval(Math.max(a.start, b.start), Math.min(a.end, b.end)); 18 | } 19 | } 20 | 21 | public static Interval union(Interval a, Interval b) { 22 | if(!isIntersect(a, b)) { 23 | return null; 24 | } else { 25 | return new Interval(Math.min(a.start, b.start), Math.max(a.end, b.end)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /practice/src/main/java/Knapsack1.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 9/25/15. 3 | */ 4 | public class Knapsack1 { 5 | } 6 | -------------------------------------------------------------------------------- /practice/src/main/java/LargestNumber.java: -------------------------------------------------------------------------------- 1 | import java.util.Arrays; 2 | import java.util.Comparator; 3 | 4 | /** 5 | * Created by karthik on 7/25/15. 6 | */ 7 | public class LargestNumber { 8 | public String largestNumber(int[] nums) { 9 | Integer[] newArray = new Integer[nums.length]; 10 | int i = 0; 11 | int numberOfDigits = 0; 12 | for (int value : nums) { 13 | if(value != 0) { 14 | numberOfDigits += (int) (Math.log10(value) + 1); 15 | } else { 16 | numberOfDigits += 1; 17 | } 18 | newArray[i++] = Integer.valueOf(value); 19 | } 20 | 21 | final int a = numberOfDigits; 22 | 23 | Arrays.sort(newArray, new Comparator() { 24 | public int compare(Integer o1, Integer o2) { 25 | double o1Digits = (o1 == 0) ? 1 : ((int) (Math.log10(o1) + 1)); 26 | double o2Digits = (o2 == 0) ? 1 : ((int) (Math.log10(o2) + 1)); 27 | if((Math.pow(10, a-o1Digits) * o1 + o2) > (Math.pow(10, a-o2Digits) * o2 + o1)) { 28 | return -1; 29 | } else if((Math.pow(10, a-o2Digits) * o2 + o1) > (Math.pow(10, a-o1Digits) * o1 + o2)) { 30 | return 1; 31 | } else { 32 | return 0; 33 | } 34 | } 35 | }); 36 | 37 | StringBuffer buf = new StringBuffer(); 38 | for(Integer num : newArray) { 39 | buf.append(num.toString()); 40 | } 41 | if(buf.toString().matches("0*")) { 42 | return "0"; 43 | } else { 44 | return buf.toString(); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /practice/src/main/java/LineSweep.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.Stack; 3 | 4 | /** 5 | * Created by karthik on 8/27/15. 6 | */ 7 | public class LineSweep { 8 | //assume that the array indices give the x axis of the points 9 | List lineSweep(int[] points) { 10 | Stack s = new Stack(); 11 | 12 | for(int i=0;i < points.length; i++) { 13 | if(s.isEmpty()) { 14 | s.push(points[i]); 15 | } else { 16 | while(!s.isEmpty() && s.peek() > points[i]) { 17 | s.pop(); 18 | } 19 | s.push(points[i]); 20 | } 21 | } 22 | return s.subList(0, s.size() -1); 23 | } 24 | } -------------------------------------------------------------------------------- /practice/src/main/java/LongestIncreasingSubarray.java: -------------------------------------------------------------------------------- 1 | import java.util.List; 2 | import java.util.Stack; 3 | 4 | /** 5 | * Created by karthik on 2/7/16. 6 | */ 7 | public class LongestIncreasingSubarray { 8 | public static void main(String[] args) { 9 | } 10 | 11 | public static Tuple solution(List list) { 12 | int maxLength = 1; 13 | Tuple pair = new Tuple(0,0); 14 | 15 | if(list.size() == 1) { 16 | return pair; 17 | } 18 | 19 | int prev = list.get(0); 20 | 21 | int start = 0; 22 | int i = 1; 23 | 24 | while( i < list.size()) { 25 | if(list.get(i) > prev) { 26 | if( i - start + 1 > maxLength) { 27 | maxLength = i-start+1; 28 | pair.a = start; 29 | pair.b = i; 30 | } 31 | 32 | } else { 33 | if(i + maxLength - 1 > list.size()) { 34 | break; 35 | } 36 | start = i; 37 | } 38 | prev = list.get(i); 39 | i++; 40 | } 41 | 42 | return pair; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /practice/src/main/java/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 9/22/15. 3 | */ 4 | import java.io.BufferedReader; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.util.StringTokenizer; 8 | 9 | public class Main { 10 | public static void main(String[] args) { 11 | 12 | } 13 | } 14 | 15 | class LineReader { 16 | public static String[] LineReader(int numberLines) { 17 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 18 | StringTokenizer token = new StringTokenizer(""); 19 | 20 | long count = 0; 21 | String temp[] = null; 22 | for (int i = 0; i < numberLines; ++i) { 23 | try { 24 | temp = br.readLine().split(" "); 25 | } catch(Exception e) {} 26 | int u = Integer.parseInt(temp[0]); 27 | int v = Integer.parseInt(temp[1]); 28 | 29 | } 30 | return temp; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /practice/src/main/java/MaxDifference.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 1/13/16. 3 | */ 4 | public class MaxDifference { 5 | //Given an array return the max difference between any two indices i, j where i < j 6 | public static int maxDifference(int[] a) { 7 | int maxDiff = 0; 8 | int minSoFar = a[0]; 9 | int maxSoFar = a[0]; 10 | for(int i=0;i maxSoFar) { 15 | maxSoFar = a[i]; 16 | } 17 | maxDiff = Math.max(maxDiff, maxSoFar - minSoFar); 18 | } 19 | return maxDiff; 20 | } 21 | 22 | public static int maxFlatLine(int[] a) { 23 | if(a.length == 0) { 24 | return 0; 25 | } else { 26 | int maxLength = 1; 27 | int currentIndex = -1; 28 | int prev = Integer.MAX_VALUE; 29 | for(int i=0;i mapping = new HashMap<>(); 9 | public static void main(String[] args) { 10 | System.out.print(isMatch("aabbaa", "abcdabcdffabcdabcd")); 11 | System.out.print(isMatch("a", "")); 12 | } 13 | 14 | public static boolean isMatch(String pattern, String word) { 15 | if(word.isEmpty() && pattern.isEmpty()) { 16 | return true; 17 | } else if(pattern.isEmpty()){ 18 | return false; 19 | } else if(word.isEmpty()) { 20 | return false; 21 | } else { 22 | String patternToConsider = pattern.substring(0, 1); 23 | if(mapping.containsKey(patternToConsider)) { 24 | String wordMap = mapping.get(patternToConsider); 25 | String nextWord = word.substring(0, Math.min(wordMap.length(), word.length())); 26 | if(!nextWord.equals(wordMap)) { 27 | return false; 28 | } else { 29 | return isMatch(pattern.substring(1), word.substring(wordMap.length())); 30 | } 31 | } else { 32 | for(int i=0; i m = new HashMap(); 11 | 12 | for(int i=0;icolMin && colOffset < colMax && rowOffset == rowMin) { 24 | colOffset++; 25 | } else if(colOffset == colMax && rowOffset < rowMax) { 26 | rowOffset++; 27 | rowMin++; 28 | } else if(colOffset == colMax && (rowOffset > rowMin)) { 29 | colOffset--; 30 | } else if(colOffset > colMin && rowOffset == rowMax) { 31 | colMax--; 32 | } else if(colOffset == colMin && rowOffset == rowMax) { 33 | rowOffset--; 34 | rowMax--; 35 | } else if(colOffset == colMin && rowOffset > rowMin) { 36 | rowOffset--; 37 | } else if(colOffset == colMin && rowOffset == rowMin) { 38 | colMin++; 39 | } 40 | i++; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /practice/src/main/java/RemoveParent.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayList; 2 | import java.util.List; 3 | 4 | /** 5 | * Created by karthik on 2/28/16. 6 | */ 7 | public class RemoveParent { 8 | // This just removes the extra ")" parenthesis 9 | 10 | public static List removeInvalidParentheses(String s) { 11 | List ans = new ArrayList<>(); 12 | remove(s, ans, 0, 0, new char[]{'(', ')'}); 13 | return ans; 14 | } 15 | 16 | public static void remove(String s, List ans, int last_i, int last_j, char[] par) { 17 | int stack = 0, i; 18 | for (i = last_i; i < s.length(); ++i) { 19 | if (s.charAt(i) == par[0]) stack++; 20 | if (s.charAt(i) == par[1]) stack--; 21 | if (stack < 0) { 22 | for (int j = last_j; j <= i; ++j) { 23 | if (s.charAt(j) == par[1] && (j == last_j || s.charAt(j - 1) != par[1])) 24 | remove(s.substring(0, j) + s.substring(j + 1, s.length()), ans, i, j, par); 25 | } 26 | return; 27 | } 28 | } 29 | String reversed = new StringBuilder(s).reverse().toString(); 30 | if (par[0] == '(') 31 | remove(reversed, ans, 0, 0, new char[]{')', '('}); 32 | else 33 | ans.add(reversed); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /practice/src/main/java/RotateArray.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 2/7/16. 3 | */ 4 | public class RotateArray { 5 | public static int[] solution(int[] a, int k) { 6 | reverseArray(a, 0, a.length -1, k); 7 | reverseArray(a, 0, k-1, k-1); 8 | reverseArray(a, k, a.length-1, k-1); 9 | return a; 10 | } 11 | public static void reverseArray(int[] a, int start, int end, int k) { 12 | for(int i=0;i target) { 14 | hi = mid -1 ; 15 | } else if(a[mid] == target) { 16 | hi = mid; 17 | } else { 18 | lo = mid + 1; 19 | } 20 | } 21 | return (a[hi] == target)? hi : -1; 22 | } 23 | 24 | // Given a sequnce like \xxxxxxxxxxxx/ 25 | public static int findLocalMinima(int[] a){ 26 | //okay the key insight is that the first two decrease and the last two increase 27 | 28 | int lo = 1; 29 | int hi = a.length-2; 30 | 31 | while(lo <= hi) { 32 | int mid = lo + (hi - lo)/2; 33 | 34 | if(a[mid] <= a[mid-1] && a[mid] <= a[mid+1]) { 35 | return mid; 36 | } else if(a[mid] > a[a.length-2]) { 37 | lo = mid + 1 ; 38 | } else if(a[mid] > a[1]) { 39 | hi = mid - 1; 40 | } else if(a[mid] < a[a.length -2]) { 41 | hi = mid -1; 42 | } else if(a[mid] < a[1]) { 43 | lo = mid + 1; 44 | } else { 45 | lo = mid + 1; 46 | } 47 | } 48 | 49 | return lo; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /practice/src/main/java/SlidingMax.java: -------------------------------------------------------------------------------- 1 | import java.util.ArrayDeque; 2 | import java.util.ArrayList; 3 | import java.util.Deque; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by karthik on 7/22/15. 8 | */ 9 | public class SlidingMax { 10 | public int[] maxSlidingWindow(int[] nums, int k) { 11 | if(k == 1) { 12 | return nums; 13 | } 14 | 15 | ArrayList ans = new ArrayList(); 16 | int i=0; 17 | Deque q = new ArrayDeque(); 18 | 19 | while( i < nums.length ) { 20 | int element = nums[i]; 21 | 22 | while(!q.isEmpty() && nums[q.peekLast()] < element) { 23 | q.removeLast(); 24 | } 25 | 26 | q.addLast(i); 27 | 28 | if(i >= k-1) { 29 | int maxIndex = q.peekFirst(); 30 | ans.add(nums[maxIndex]); 31 | 32 | if(maxIndex <= (i-k+1)) { 33 | q.removeFirst(); 34 | } 35 | } 36 | i++; 37 | } 38 | return buildIntArray(ans); 39 | } 40 | 41 | private int[] buildIntArray(List integers) { 42 | int[] ints = new int[integers.size()]; 43 | int i = 0; 44 | for (Integer n : integers) { 45 | ints[i++] = n; 46 | } 47 | return ints; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /practice/src/main/java/StreamingMedian.java: -------------------------------------------------------------------------------- 1 | import java.util.PriorityQueue; 2 | 3 | /** 4 | * Created by karthik on 1/28/16. 5 | */ 6 | public class StreamingMedian { 7 | 8 | } 9 | 10 | 11 | -------------------------------------------------------------------------------- /practice/src/main/java/Summary.java: -------------------------------------------------------------------------------- 1 | import java.util.HashMap; 2 | 3 | /** 4 | * Created by karthik on 8/8/15. 5 | */ 6 | public class Summary { 7 | String getSummary(String[] document, String[] query) { 8 | HashMap queryMap = new HashMap(); 9 | 10 | for(String word: query) { 11 | 12 | } 13 | return ""; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /practice/src/main/java/Tuple.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 2/7/16. 3 | */ 4 | public class Tuple { 5 | A a; 6 | B b; 7 | 8 | public Tuple(A a, B b) { 9 | this.a= a; 10 | this.b= b; 11 | } 12 | 13 | public Tuple(){ 14 | 15 | } 16 | } 17 | 18 | 19 | -------------------------------------------------------------------------------- /practice/src/main/java/WalkArray.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Created by karthik on 1/12/16. 3 | */ 4 | public class WalkArray { 5 | public static int arrayWalk(int[] array) { 6 | 7 | if(array.length == 0) { 8 | return 1; 9 | } 10 | int[] path = new int[array.length]; 11 | int step = 1; 12 | int maxStep = array[0]; 13 | path[0] = maxStep; 14 | 15 | for(int i=1;i= i) { 18 | maxStep = path[i-1]; 19 | step++; 20 | } else { 21 | return -1; 22 | } 23 | } 24 | path[i] = Math.max(path[i-1], i+ array[i]); 25 | } 26 | return step; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /practice/src/main/java/codeforces/BinarySearch.java: -------------------------------------------------------------------------------- 1 | package codeforces; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Created by karthik on 2/2/16. 7 | */ 8 | public class BinarySearch { 9 | public static void main(String [] args) { 10 | // 11 | } 12 | 13 | public static int binarySearch(List list, int target) { 14 | int lo = 0; 15 | int hi = list.size() -1; 16 | 17 | while(lo <= hi) { 18 | int mid = lo + (hi - lo)/2; // avoids overflow 19 | int element = list.get(mid); 20 | 21 | if(element == target) { 22 | return mid; 23 | } else if(element > target) { 24 | hi = mid - 1; 25 | } else { 26 | lo = mid + 1; 27 | } 28 | } 29 | 30 | return -1; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /practice/src/main/java/codeforces/P112A.java: -------------------------------------------------------------------------------- 1 | package codeforces; 2 | 3 | /** 4 | * Created by karthik on 12/26/15. 5 | */ 6 | public class P112A { 7 | public static void main(String[] args) { 8 | MyScanner reader = new MyScanner(); 9 | String input1 = reader.nextLine(); 10 | String input2 = reader.nextLine(); 11 | System.out.print(solution(input1, input2)); 12 | } 13 | 14 | public static String solution(String input1, String input2) { 15 | assert (input1.length() == input2.length()); 16 | 17 | for(int i=0; i < input1.length();i++) { 18 | char a = Character.toLowerCase(input1.charAt(i)); 19 | char b = Character.toLowerCase(input2.charAt(i)); 20 | if(a < b) { 21 | return "-1"; 22 | } else if (a > b) { 23 | return "1"; 24 | } 25 | } 26 | return "0"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /practice/src/main/java/codeforces/P115A.java: -------------------------------------------------------------------------------- 1 | package codeforces; 2 | 3 | import java.util.ArrayList; 4 | 5 | /** 6 | * Created by karthik on 1/26/16. 7 | */ 8 | public class P115A { 9 | public static void main(String[] args) { 10 | MyScanner s = new MyScanner(); 11 | int n = s.nextInt(); 12 | ArrayList> dep = new ArrayList>(n); 13 | 14 | for(int i=0;i()); 16 | } 17 | 18 | for(int i=0;i neigh = new ArrayList(); 22 | neigh.add(i); 23 | dep.set(manager-1, neigh); 24 | } else if(manager != -1) { 25 | dep.get(manager-1).add(i); 26 | } 27 | } 28 | //System.out.println(dep); 29 | System.out.println(solution(n, dep)); 30 | } 31 | 32 | public static int solution(int n, ArrayList> neighbors) { 33 | int max = Integer.MIN_VALUE; 34 | 35 | for(int i=0;i> neighbors) { 42 | int height = 0; 43 | for(Integer neighbor : neighbors.get(n)) { 44 | height = Math.max(height, dfs(neighbor, neighbors)); 45 | } 46 | return height + 1; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /practice/src/main/java/codeforces/P160A.java: -------------------------------------------------------------------------------- 1 | package codeforces; 2 | 3 | import java.util.Arrays; 4 | import java.util.Collections; 5 | import java.util.List; 6 | 7 | /** 8 | * Created by karthik on 12/26/15. 9 | */ 10 | public class P160A { 11 | public static void main(String[] args) { 12 | MyScanner reader = new MyScanner(); 13 | int n = reader.nextInt(); 14 | String line = reader.nextLine(); 15 | System.out.print(solution(n, reader.toInt(line.split(" ")))); 16 | } 17 | 18 | public static int solution(int n, List a) { 19 | Collections.sort(a, Collections.reverseOrder()); 20 | 21 | int sum = 0; 22 | for(Integer i : a) { 23 | sum += i; 24 | } 25 | 26 | int takenSum=0; 27 | int i =0; 28 | while(takenSum <= (sum - takenSum)) { 29 | takenSum += a.get(i); 30 | i++; 31 | } 32 | return i; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /practice/src/main/java/codeforces/P253B.java: -------------------------------------------------------------------------------- 1 | package codeforces; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | 6 | /** 7 | * Created by karthik on 12/27/15. 8 | * The idea is to see the fastest route from either end of yhe 9 | * mountains to attain quilibyrium. There is a half way point 10 | * 11 | */ 12 | public class P253B { 13 | public static void main(String[] args) { 14 | MyScanner reader = new MyScanner(); 15 | int n = reader.nextInt(); 16 | String line = reader.nextLine(); 17 | System.out.print(solution(n, reader.toInt(line.split(" ")))); 18 | } 19 | 20 | public static int solution(int n, List a) { 21 | Collections.sort(a); 22 | 23 | int i = 0; 24 | int j= 0; 25 | 26 | return 0; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /practice/src/main/java/codeforces/P330B.java: -------------------------------------------------------------------------------- 1 | package codeforces; 2 | 3 | import java.util.BitSet; 4 | 5 | /** 6 | * Created by karthik on 1/29/16. 7 | */ 8 | public class P330B { 9 | public static void main(String[] args) { 10 | MyScanner s = new MyScanner(); 11 | int n = s.nextInt(); 12 | int m = s.nextInt(); 13 | 14 | BitSet bs = new BitSet(1000); 15 | 16 | for(int i=0;i= prev) { 20 | count++; 21 | } else { 22 | count = 1; 23 | } 24 | maxCount = max(maxCount, count); 25 | prev = a[i]; 26 | } 27 | return maxCount; 28 | } 29 | 30 | public static int max(int a, int b) { 31 | if(a > b) { 32 | return a; 33 | } else { 34 | return b; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /practice/src/main/scala/Judge.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.JavaConverters 2 | 3 | /** 4 | * Created by karthik on 7/19/15. 5 | */ 6 | object Judge { 7 | def main(args: Array[String]) = { 8 | val dnf = new DNF() 9 | println(dnf.dutchNationalFlag(Array(2,1,0,0,0,0,0,0,0)).toList) 10 | println(dnf.dutchNationalFlag(Array(2,1)).toList) 11 | println(dnf.dutchNationalFlag(Array(2,0,0,0)).toList) 12 | println(dnf.dutchNationalFlag(Array(2,1,0,2,0,1)).toList) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /practice/src/main/scala/Solutions.scala: -------------------------------------------------------------------------------- 1 | import scala.collection.mutable 2 | 3 | /** 4 | * Created by karthik on 9/26/15. 5 | */ 6 | object Solutions { 7 | def deDupeString(input: String) = { 8 | val stack = new mutable.Stack[Char]() 9 | var indexMap = Map[Char, Int]() 10 | var seen = Set[Char]() 11 | 12 | (0 to input.length - 1).foreach{ index => 13 | indexMap = indexMap.updated(input(index), index) 14 | } 15 | 16 | (0 to input.length - 1).foreach{ index => 17 | if(stack.isEmpty) { 18 | stack.push(input(index)) 19 | seen = seen + input(index) 20 | } else if(!seen(input(index)) && stack.head < input(index)){ 21 | stack.push(input(index)) 22 | seen = seen + input(index) 23 | } else if(!seen(input(index)) && stack.head == input(index)) { 24 | 25 | } else { 26 | while(stack.nonEmpty && indexMap(stack.head) > index) { 27 | stack.pop() 28 | } 29 | stack.push(input(index)) 30 | seen = seen + input(index) 31 | } 32 | } 33 | 34 | stack.toString() 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /practice/src/main/scala/Tree.scala: -------------------------------------------------------------------------------- 1 | import scala.annotation.tailrec 2 | import scala.collection.mutable 3 | 4 | /** 5 | * Created by karthik on 9/26/15. 6 | */ 7 | 8 | case class TreeNode(left: Option[TreeNode], right: Option[TreeNode], data: Int) 9 | 10 | 11 | class TreeOperations { 12 | 13 | def inorderSuccessor(root: TreeNode, targetNode: TreeNode): TreeNode = { 14 | val stack = new mutable.Stack[TreeNode]() 15 | 16 | var traverse:Option[TreeNode] = Some(root) 17 | 18 | while(traverse.isDefined && traverse.get.data != targetNode.data) { 19 | stack.push(traverse.get) 20 | if(traverse.get.data < targetNode.data) { 21 | traverse = traverse.get.right 22 | } else { 23 | traverse = traverse.get.left 24 | } 25 | } 26 | 27 | if(traverse.isDefined) { 28 | if(traverse.get.right.isDefined) { 29 | return findLeftMost(traverse.get.right.get) 30 | } else { 31 | var bottomUpTraverse: TreeNode = traverse.get 32 | 33 | while(bottomUpTraverse != root) { 34 | val parent = stack.pop() 35 | if(parent.left == bottomUpTraverse) { 36 | return parent 37 | } else { 38 | bottomUpTraverse = parent 39 | } 40 | } 41 | return bottomUpTraverse 42 | } 43 | } else { 44 | throw new RuntimeException("target element node found") 45 | } 46 | } 47 | 48 | @tailrec 49 | final def findLeftMost(node: TreeNode): TreeNode = { 50 | if(node.left.isEmpty) { 51 | return node 52 | } else { 53 | return findLeftMost(node) 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /practice/src/test/scala/AnagramTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | import scala.collection.JavaConversions._ 3 | /** 4 | * Created by karthik on 8/9/15. 5 | */ 6 | class Anagramtest extends FlatSpec with Matchers { 7 | //val o = new Anagram() 8 | val p = new WordLadder() 9 | 10 | // "anagram" should "be true" in { 11 | // o.isAnagram("car", "rac") should be (true) 12 | // o.isAnagram("car", "car") should be (true) 13 | // o.isAnagram("aaaa", "aaaa") should be (true) 14 | // o.isAnagram("", "") should be (true) 15 | // } 16 | // 17 | // "anagram" should "be false " in { 18 | // o.isAnagram("car", "rrac") should be (false) 19 | // o.isAnagram("car", "aaaa") should be (false) 20 | // o.isAnagram("aaaa", "aaaaxzzzzz") should be (false) 21 | // o.isAnagram("aaaa", "") should be (false) 22 | // } 23 | 24 | "wl" should "work" in { 25 | p.findLadders("cog", "hit", Set("hot","dot","dog","lot","log")); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /practice/src/test/scala/ArrayWalkTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 1/12/16. 5 | */ 6 | class ArrayWalkTest extends FlatSpec with Matchers { 7 | "ArrayWalk" should "work" in { 8 | WalkArray.arrayWalk(Array(2,1,2,1,0,1)) should be (-1) 9 | WalkArray.arrayWalk(Array(2,1,3,1,0,1)) should be (2) 10 | WalkArray.arrayWalk(Array(1,1)) should be (1) 11 | WalkArray.arrayWalk(Array(0,0)) should be (-1) 12 | WalkArray.arrayWalk(Array(0,0)) should be (-1) 13 | WalkArray.arrayWalk(Array(3,3,0,2)) should be (1) 14 | WalkArray.arrayWalk(Array(3,3,0,2,0,3,1,0,1)) should be (3) 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /practice/src/test/scala/BinarySearchTest.scala: -------------------------------------------------------------------------------- 1 | import codeforces.BinarySearch 2 | import org.scalatest.{FlatSpec, Matchers} 3 | import scala.collection.JavaConverters._ 4 | import scala.util.Random 5 | 6 | /** 7 | * Created by karthik on 2/2/16. 8 | */ 9 | class BinarySearchTest extends FlatSpec with Matchers { 10 | "BINARY SEARCH" should "work" in { 11 | for (i <- 1 to 100) { 12 | val list = List.fill(100)(Random.nextInt()) 13 | val numberIndex = Random.nextInt(list.size) 14 | BinarySearch.binarySearch(list.map(x => new Integer(x)).asJava, list(numberIndex)) should be (numberIndex) 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /practice/src/test/scala/CombinationsTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | import scala.collection.JavaConverters._ 3 | 4 | /** 5 | * Created by karthik on 2/28/16. 6 | */ 7 | class CombinationsTest extends FlatSpec with Matchers { 8 | val sut = new Combinations 9 | val sut2 = new Combinations2 10 | 11 | 12 | "Combinations2" should "wrok" in { 13 | println(sut2.combine(9, 3)) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /practice/src/test/scala/CountingSortTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 1/10/16. 5 | */ 6 | class CountingSortTest extends FlatSpec with Matchers { 7 | "Counting sort" should "work" in { 8 | val a = Array(5,3,2,4,5,2,1) 9 | 10 | CountingSort.sort(a) 11 | 12 | println(a.toList) 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /practice/src/test/scala/DNFTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest._ 2 | import scala.concurrent.JavaConversions._ 3 | /** 4 | * Created by karthik on 7/19/15. 5 | */ 6 | 7 | class InterviewTest extends FlatSpec with Matchers { 8 | 9 | val dnf = new DNF() 10 | 11 | // "DNF" should "work on randomized inputs" in { 12 | // (1 to 100).foreach { i => 13 | // val a = randomArray(100, 2) 14 | // dnf.dutchNationalFlag(a) should be(a.sorted) 15 | // } 16 | // } 17 | 18 | // "Slidingmax test" should "work" in { 19 | // val s = new SlidingMax(); 20 | // val ans = s.maxSlidingWindow(Array(4,3,2,1,0,10,11,12,14), 5) 21 | // println(ans.toList) 22 | // } 23 | 24 | "Largest Number " should "work" in { 25 | val s = new LargestNumber(); 26 | val ans = s.largestNumber(Array(0,0, 0, 9)) 27 | println(ans) 28 | } 29 | 30 | def randomArray(n: Int, range: Int): Array[Int] = { 31 | var a:Array[Int] = new Array[Int](n) 32 | for (index <- 0 to a.length - 1) a(index) = (randInt(range)) 33 | a 34 | } 35 | def randInt(range: Int): Int = { 36 | val rnd = new scala.util.Random 37 | rnd.nextInt(range) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /practice/src/test/scala/DeleteArrayTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | import scala.collection.JavaConverters._ 3 | /** 4 | * Created by karthik on 1/12/16. 5 | */ 6 | class DeleteArrayTest extends FlatSpec with Matchers { 7 | "DeleteArray" should "work" in { 8 | DeleteArray.deleteArray(Array(1,2,6,4,5,6), 6).toList.take(4) should be(Array(1,2,4,5)) 9 | DeleteArray.deleteArray(Array(1,2), 1).toList.take(1) should be(Array(2)) 10 | DeleteArray.deleteArray(Array(1,2, 2, 2, 1,1, 3,3,3,3), 1).toList.take(7) should be(Array(2, 2, 2, 3, 3, 3, 3)) 11 | DeleteArray.deleteDuplicates(Array(1,2, 2, 2,3,3,3)).toList.take(3) should be(Array(1,2,3)) 12 | DeleteArray.deleteDuplicates(Array(1,2, 2, 2,2,2)).toList.take(2) should be(Array(1,2)) 13 | DeleteArray.deleteDuplicates(Array(1,2, 2, 2,2,2), 3).toList.take(4) should be(Array(1,2, 2, 2)) 14 | DeleteArray.deleteDuplicates(Array(1,1, 1, 2,2), 3).toList.take(4) should be(Array(1,1,2,2)) 15 | DeleteArray.deleteDuplicates(Array(1,1, 1, 2,2,2,3,4), 3).toList.take(6) should be(Array(1,1,2,2,3,4)) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /practice/src/test/scala/ExpressionEvaluator.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | import scala.collection.JavaConverters._ 3 | 4 | /** 5 | * Created by karthik on 2/22/16. 6 | */ 7 | class ExpressionEvaluatorTest extends FlatSpec with Matchers { 8 | "This" should "work" in { 9 | ExpressionEvaluator.computeExpression("1+2*3").asScala.toSet should be (Set(7, 9)) 10 | println(ExpressionEvaluator.computeExpression("1*2+3*4").asScala.toSet) 11 | println(ExpressionEvaluator.computeExpression("1/2*3+5").asScala.toSet) 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /practice/src/test/scala/FindDuplicateTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 3/20/16. 5 | */ 6 | class FindDuplicateTest extends FlatSpec with Matchers { 7 | "Duplicate " should "work" in { 8 | FindDuplicate.solution(Array(1, 1, 2)) should be(1) 9 | FindDuplicate.solution(Array(1, 2, 2)) should be(2) 10 | FindDuplicate.solution(Array(1, 2, 3,3)) should be(3) 11 | FindDuplicate.solution(Array(3,1,3,2)) should be(3) 12 | FindDuplicate.solution(Array(1,1,1,1)) should be(1) 13 | FindDuplicate.solution(Array(3,3,3,3)) should be(3) 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /practice/src/test/scala/HashTables.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 1/16/16. 5 | */ 6 | class HashTablesTest extends FlatSpec with Matchers { 7 | "Longest distinct" should "work" in { 8 | HashTables.longestDistinctArray(Array(1)) should be (1) 9 | HashTables.longestDistinctArray(Array(1, 2)) should be (2) 10 | HashTables.longestDistinctArray(Array(1, 2, 1, 3, 4, 5, 3, 100, 4, 3)) should be (5) 11 | 12 | HashTables.longestContainedInterval(Array(1,2,3,233,355,67,7,8,9,10)) should be (4) 13 | HashTables.longestContainedInterval(Array(1,2,3,233,355,67,4,5,9,10)) should be (5) 14 | HashTables.longestContainedInterval(Array(1,1,1,1,2,2,2,4,4,4)) should be (2) 15 | HashTables.longestContainedInterval(Array(1,2,3,4,5,6,7)) should be (7) 16 | HashTables.longestContainedInterval(Array(1)) should be (1) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /practice/src/test/scala/IntervalTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 1/9/16. 5 | */ 6 | class IntervalTest extends FlatSpec with Matchers { 7 | "isINtersect" should "work" in { 8 | IntervalStuff.isIntersect(new Interval(1, 5), new Interval(2, 6)) should be (true) 9 | IntervalStuff.isIntersect(new Interval(1, 2), new Interval(4, 6)) should be (false) 10 | IntervalStuff.isIntersect(new Interval(1, 8), new Interval(3, 5)) should be (true) 11 | } 12 | 13 | "Intersect" should "work" in { 14 | val a = IntervalStuff.intersect(new Interval(1, 8), new Interval(3, 5)) 15 | val b = IntervalStuff.intersect(new Interval(1, 8), new Interval(3, 10)) 16 | val c = IntervalStuff.intersect(new Interval(1, 8), new Interval(9, 10)) 17 | 18 | a.start should be (3) 19 | a.end should be (5) 20 | 21 | b.start should be (3) 22 | b.end should be (8) 23 | 24 | c should be (null) 25 | 26 | } 27 | 28 | "Union" should "work" in { 29 | val a = IntervalStuff.union(new Interval(1, 8), new Interval(3, 5)) 30 | val b = IntervalStuff.union(new Interval(1, 8), new Interval(3, 10)) 31 | val c = IntervalStuff.union(new Interval(1, 8), new Interval(9, 10)) 32 | 33 | a.start should be (1) 34 | a.end should be (8) 35 | 36 | b.start should be (1) 37 | b.end should be (10) 38 | 39 | c should be (null) 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /practice/src/test/scala/InvalidParenTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 2/28/16. 5 | */ 6 | class InvalidParenTest extends FlatSpec with Matchers { 7 | 8 | "invalid" should "work" in { 9 | println(RemoveParent.removeInvalidParentheses("(())())")) 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /practice/src/test/scala/IpAddressTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | import scala.collection.JavaConverters._ 3 | /** 4 | * Created by karthik on 2/29/16. 5 | */ 6 | class IpAddressTest extends FlatSpec with Matchers { 7 | "THis" should "work" in { 8 | println(IpAddress.restoreIpAddresses("11")) 9 | println(IpAddress.restoreIpAddresses("25525511135")) 10 | println(IpAddress.restoreIpAddresses("0")) 11 | println(IpAddress.restoreIpAddresses("0000")) 12 | println(IpAddress.restoreIpAddresses("00000")) 13 | println(IpAddress.restoreIpAddresses("00000123")) 14 | println(IpAddress.restoreIpAddresses("111112")) 15 | println(IpAddress.restoreIpAddresses("11119802")) 16 | println(IpAddress.restoreIpAddresses("12341221123")) 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /practice/src/test/scala/JustifyTextTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | import scala.collection.JavaConverters._ 3 | /** 4 | * Created by karthik on 2/10/16. 5 | */ 6 | class JustifyTextTest extends FlatSpec with Matchers{ 7 | "JustifyText" should "work" in { 8 | println(JustifyText.solution(Array("the", "cat" ,"climbed", "the", "clock"), 10).asScala.mkString("\n")) 9 | println(JustifyText.solution(Array("the", "cat" ,"climbed", "the", "clock"), 2).asScala.mkString("\n")) 10 | println(JustifyText.solution(Array("the", "cat" ,"climbed", "the", "clock"), 1).asScala.mkString("\n")) 11 | println(JustifyText.solution(Array("the"), 13).asScala.mkString("\n")) 12 | //println(JustifyText.solution(Array("the"),).asScala.mkString("\n")) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /practice/src/test/scala/LongestIncreasingTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | import scala.collection.JavaConverters._ 3 | 4 | /** 5 | * Created by karthik on 2/7/16. 6 | */ 7 | class LongestIncreasingTest extends FlatSpec with Matchers { 8 | "LIS" should "work" in { 9 | val ans = LongestIncreasingSubarray.solution(List(1,2,3,4).map(Int.box).asJava) 10 | ans.a should be (0) 11 | ans.b should be (3) 12 | 13 | val ans1 = LongestIncreasingSubarray.solution(List(1,2,3,4, -1, 0, 1, 2, 3, 5).map(Int.box).asJava) 14 | ans1.a should be (4) 15 | ans1.b should be (9) 16 | 17 | val ans2 = LongestIncreasingSubarray.solution(List(10,9,8).map(Int.box).asJava) 18 | ans2.a should be (0) 19 | ans2.b should be (0) 20 | 21 | val ans3 = LongestIncreasingSubarray.solution(List(2,11,3,5,13,7,19,17,23).map(Int.box).asJava) 22 | ans3.a should be (2) 23 | ans3.b should be (4) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /practice/src/test/scala/MaxDifferenceTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 1/13/16. 5 | */ 6 | class MaxDifferenceTest extends FlatSpec with Matchers { 7 | "MaxDifference" should "work" in { 8 | MaxDifference.maxDifference(Array(1,2,3,77,9)) should be (76) 9 | MaxDifference.maxDifference(Array(1,10)) should be (9) 10 | MaxDifference.maxDifference(Array(1, 10, 14, 16, 20)) should be (19) 11 | MaxDifference.maxDifference(Array(1, 10, 14, 16, 20, 0, 100)) should be (100) 12 | MaxDifference.maxFlatLine(Array(1, 10, 14, 16, 20, 0, 100)) should be (1) 13 | MaxDifference.maxFlatLine(Array(1, 10,10,10, 14,14)) should be (3) 14 | MaxDifference.maxFlatLine(Array(1, 10,10,10, 14,14,14,14)) should be (4) 15 | MaxDifference.maxFlatLine(Array(1)) should be (1) 16 | MaxDifference.maxFlatLine(Array(1,1,1,1,1)) should be (5) 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /practice/src/test/scala/MaxGapTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 1/11/16. 5 | */ 6 | class MaxGapTest extends FlatSpec with Matchers { 7 | "MaxGap" should "correct" in { 8 | MaxGap.maximumGap(Array(9, 6, 1, 4)) should be (3) 9 | MaxGap.maximumGap(Array(1, 15, 50, 75, 100)) should be (35) 10 | MaxGap.maximumGap(Array(1, 2)) should be (1) 11 | MaxGap.maximumGap(Array(1, 12)) should be (11) 12 | MaxGap.maximumGap(Array(1, 1, 1, 1, 4)) should be (3) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /practice/src/test/scala/MedianTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | import scala.util.Random 4 | 5 | /** 6 | * Created by karthik on 1/31/16. 7 | */ 8 | class MedianTest extends FlatSpec with Matchers { 9 | 10 | "Median" should "work" in { 11 | var i = 0 12 | while( i < 100) { 13 | val median = new OneStreamingMedian 14 | val array = Seq.fill(Random.nextInt(1000))(Random.nextInt(120000)) 15 | println(array) 16 | val sorted = array.sorted 17 | array.foreach(median.add(_)) 18 | val mid = array.length/2; 19 | if(!array.isEmpty && array.length % 2 == 0) { 20 | median.findMedian() should equal((sorted(mid) + sorted(mid-1))/2.0f) 21 | } else if(!array.isEmpty){ 22 | median.findMedian() should equal(sorted(mid)) 23 | } 24 | i += 1 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /practice/src/test/scala/MinWindowStringtest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 2/20/16. 5 | */ 6 | class MinWindowStringtest extends FlatSpec with Matchers { 7 | "minindow" should "work" in { 8 | MinWindowString.minWindow("a", "aa") should be ("a") 9 | MinWindowString.minWindow("aafggg", "af") should be ("af") 10 | MinWindowString.minWindow("adobebanc", "abc") should be ("banc") 11 | MinWindowString.minWindow("aafggg", "rrt") should be ("") 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /practice/src/test/scala/OperatorComboTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{FlatSpec, Matchers} 2 | 3 | /** 4 | * Created by karthik on 3/6/16. 5 | */ 6 | class OperatorComboTest extends FlatSpec with Matchers{ 7 | val sut = new OperatorCombo 8 | "Opeator Combo" should "work" in { 9 | println(sut.addOperators("0", 0)) 10 | println(sut.addOperators("01", 0)) 11 | println(sut.addOperators("01", 1)) 12 | println(sut.addOperators("00",0)) 13 | println(sut.addOperators("0011222",2)) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /practice/src/test/scala/P112ATest.scala: -------------------------------------------------------------------------------- 1 | import codeforces.P112A 2 | import org.scalatest.{Matchers, FlatSpec} 3 | 4 | /** 5 | * Created by karthik on 12/26/15. 6 | */ 7 | class P112ATest extends FlatSpec with Matchers { 8 | "1. CompareString" should "return 0" in { 9 | P112A.solution("aaaa", "aaaA") should be ("0") 10 | } 11 | 12 | "2. CompareString" should "return 1" in { 13 | P112A.solution("abs", "abZ") should be ("-1") 14 | } 15 | 16 | "3. CompareString" should "return -1" in { 17 | P112A.solution("abcdefg", "AbCdEfF") should be ("1") 18 | } 19 | 20 | "4. CompareString" should "return 1" in { 21 | P112A.solution("Z", "A") should be ("1") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /practice/src/test/scala/P160Test.scala: -------------------------------------------------------------------------------- 1 | import codeforces.{P160A, P112A} 2 | import org.scalatest.{Matchers, FlatSpec} 3 | import scala.collection.JavaConverters._ 4 | import scala.collection.mutable 5 | 6 | /** 7 | * Created by karthik on 12/26/15. 8 | */ 9 | class P160ATest extends FlatSpec with Matchers { 10 | "p160ATest" should "correct" in { 11 | P160A.solution(2, mutable.MutableList(3, 3).map(int2Integer).asJava) should be (2) 12 | P160A.solution(3, mutable.MutableList(2, 1, 2).map(int2Integer).asJava) should be (2) 13 | P160A.solution(1, mutable.MutableList(1).map(int2Integer).asJava) should be (1) 14 | P160A.solution(4, mutable.MutableList(4,3,2,1).map(int2Integer).asJava) should be (2) 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /practice/src/test/scala/P327ATest.scala: -------------------------------------------------------------------------------- 1 | import codeforces.{P327A, P160A} 2 | import org.scalatest.{Matchers, FlatSpec} 3 | 4 | import scala.collection.mutable 5 | 6 | /** 7 | * Created by karthik on 1/5/16. 8 | */ 9 | class P327ATest extends FlatSpec with Matchers{ 10 | "p327A" should "correct" in { 11 | P327A.solution(1, Array(1)) should be (0) 12 | P327A.solution(1, Array(0)) should be (1) 13 | 14 | P327A.solution(2, Array(0, 0 )) should be (2) 15 | P327A.solution(1, Array(1,0)) should be (2) 16 | P327A.solution(5, Array(1,0,0,1,0)) should be (4) 17 | P327A.solution(4, Array(1,0,0,1)) should be (4) 18 | P327A.solution(4, Array(0,0,0,0)) should be (4) 19 | P327A.solution(4, Array(1,1,1,1)) should be (3) 20 | P327A.solution(100, Array(0,1,0,1,1,1,0,1,0,1,0,0,1,1,1,1,0,0,1,1,1,1,1,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1,0,0,1,1,1,0,0,1,1,0,1,1,1,0,0,0,1,0,0,0,0,0,1,1,0,0,1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1)) should be (70) 21 | } 22 | } -------------------------------------------------------------------------------- /practice/src/test/scala/P520Btest.scala: -------------------------------------------------------------------------------- 1 | import codeforces.P520B 2 | import org.scalatest.{Matchers, FlatSpec} 3 | 4 | /** 5 | * Created by karthik on 1/26/16. 6 | */ 7 | class P520Btest extends FlatSpec with Matchers { 8 | "The BFS " should "work" in { 9 | P520B.solution(4, 6) should be (2) 10 | P520B.solution(10, 1) should be (9) 11 | P520B.solution(6, 3) should be (3) 12 | P520B.solution(99, 100) should be (50) 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /practice/src/test/scala/P580ATest.scala: -------------------------------------------------------------------------------- 1 | import codeforces.P580A 2 | import org.scalatest.{Matchers, FlatSpec} 3 | 4 | /** 5 | * Created by karthik on 1/5/16. 6 | */ 7 | class P580ATest extends FlatSpec with Matchers { 8 | "p580a" should "correct" in { 9 | P580A.solution(6, Array(2,2,1,3,4,1)) should be (3) 10 | P580A.solution(1, Array(1,1,1,1)) should be (4) 11 | P580A.solution(1, Array(1,1,0,0,0)) should be (3) 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /practice/src/test/scala/RegexTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 2/16/16. 5 | */ 6 | class RegexTest extends FlatSpec with Matchers { 7 | "Regex Test" should "work" in { 8 | RegexMatch.isMatch("a", "a") should be (true) 9 | RegexMatch.isMatch("abcd", "abcd") should be (true) 10 | RegexMatch.isMatch("aabcd", "a*d") should be (true) 11 | RegexMatch.isMatch("aabcd", "a?d") should be (false) 12 | 13 | RegexMatch.isMatch("aabcd", "a*a*b*c*d*") should be (true) 14 | 15 | RegexMatch.isMatch("aadcd", "*de") should be (false) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /practice/src/test/scala/RotateArrayTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{FlatSpec, Matchers} 2 | import scala.collection.JavaConverters._ 3 | /** 4 | * Created by karthik on 2/8/16. 5 | */ 6 | class RotateArrayTest extends FlatSpec with Matchers { 7 | "rotate" should "work" in { 8 | println(RotateArray.solution(Array(1,2,3,4,9,10, 11), 2).toList) 9 | //10 9 3 4 2 1 10 | // 9 10 3 4 2 1 11 | // 9 10 1 2 3 4 12 | // 1 10 1 2 3 4 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /practice/src/test/scala/SearchesTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 1/14/16. 5 | */ 6 | class SearchesTest extends FlatSpec with Matchers { 7 | "findLocalMInial" should "work" in { 8 | Searches.findLocalMinima(Array(15, 13, 12, 18, 19, 20, 7, 6, 5, 4, 3, 2, 11)) should be (11) 9 | Searches.findLocalMinima(Array(15, 13, 13, 11, 2, 11)) should be (11) 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /practice/src/test/scala/SubstringWithUniqeTest.scala: -------------------------------------------------------------------------------- 1 | import codeforces.SubstringWithUniqe 2 | import org.scalatest.{Matchers, FlatSpec} 3 | 4 | /** 5 | * Created by karthik on 2/22/16. 6 | */ 7 | class SubstringWithUniqeTest extends FlatSpec with Matchers { 8 | "unique" should "work" in { 9 | SubstringWithUniqe.solution("abbbbb", 1) should be ("bbbbb") 10 | SubstringWithUniqe.solution("abbbbbccc", 2) should be ("bbbbbccc") 11 | SubstringWithUniqe.solution("aabbcc", 3) should be ("aabbcc") 12 | SubstringWithUniqe.solution("aabb", 3) should be ("") 13 | SubstringWithUniqe.solution("aabacbebe", 3) should be ("aabacb") 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /practice/src/test/scala/TrieTest.scala: -------------------------------------------------------------------------------- 1 | import org.scalatest.{Matchers, FlatSpec} 2 | 3 | /** 4 | * Created by karthik on 2/14/16. 5 | */ 6 | class TrieTest extends FlatSpec with Matchers { 7 | 8 | "Trie" should "work" in { 9 | val trie = new Trie() 10 | 11 | trie.insert("karthik") 12 | trie.insert("kar") 13 | trie.insert("kara") 14 | 15 | trie.insert("a") 16 | trie.insert("v") 17 | trie.insert("v") 18 | 19 | trie.search("karthik") should be (true) 20 | trie.search("kar") should be (true) 21 | trie.search("kara") should be (true) 22 | trie.search("kart") should be (false) 23 | trie.search("karh") should be (false) 24 | trie.search("karthi") should be (false) 25 | 26 | trie.startsWith("karthik") should be (true) 27 | trie.startsWith("kar") should be (true) 28 | trie.startsWith("kart") should be (true) 29 | trie.startsWith("karthi") should be (true) 30 | 31 | trie.startsWith("a") should be (true) 32 | trie.startsWith("v") should be (true) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /practice/target/.history: -------------------------------------------------------------------------------- 1 | run 2 | run Judge 3 | run ? 4 | compile 5 | update 6 | compile 7 | update 8 | sbt clean 9 | clean 10 | update 11 | compile 12 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/interview/interview$sbt_2.11/1.0/resolved.xml.properties: -------------------------------------------------------------------------------- 1 | #interview#interview$sbt_2.11;1.0 resolved revisions 2 | #Wed Mar 23 00:33:57 PDT 2016 3 | +organisation\:\#@\#\:+org.scala-sbt\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+sbt\:\#@\#\:+revision\:\#@\#\:+0.13.8\:\#@\#\:=0.13.8 release 0.13.8 null 4 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/interview/interview$sbt_2.11/1.0/resolved.xml.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/interview/interview_2.11/1.0/resolved.xml.properties: -------------------------------------------------------------------------------- 1 | #interview#interview_2.11;1.0 resolved revisions 2 | #Sun Feb 07 23:50:05 PST 2016 3 | +organisation\:\#@\#\:+org.scalatest\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+scalatest_2.11\:\#@\#\:+revision\:\#@\#\:+2.2.4\:\#@\#\:=2.2.4 release 2.2.4 null 4 | +organisation\:\#@\#\:+org.scala-lang\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+scala-library\:\#@\#\:+revision\:\#@\#\:+2.11.7\:\#@\#\:=2.11.7 ? 2.11.7 null 5 | +organisation\:\#@\#\:+org.scala-lang\:\#@\#\:+branch\:\#@\#\:+@\#\:NULL\:\#@\:\#@\#\:+module\:\#@\#\:+scala-compiler\:\#@\#\:+revision\:\#@\#\:+2.11.7\:\#@\#\:=2.11.7 release 2.11.7 null 6 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/reports/interview-interview_2.11-docs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/reports/interview-interview_2.11-optional.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/reports/interview-interview_2.11-plugin.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/reports/interview-interview_2.11-pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/reports/interview-interview_2.11-provided.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /practice/target/resolution-cache/reports/interview-interview_2.11-sources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Bits.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Bits.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/DNF.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/DNF.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Interval.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Interval.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/IntervalStuff.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/IntervalStuff.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Judge$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Judge$.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Judge.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Judge.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Knapsack1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Knapsack1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/LargestNumber$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/LargestNumber$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/LargestNumber.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/LargestNumber.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/LineReader.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/LineReader.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/LineSweep.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/LineSweep.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Main.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/PatternWordMatch.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/PatternWordMatch.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/PrefixCoveringSet.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/PrefixCoveringSet.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/SlidingMax.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/SlidingMax.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Solution.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Solution.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Solutions$$anonfun$deDupeString$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Solutions$$anonfun$deDupeString$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Solutions$$anonfun$deDupeString$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Solutions$$anonfun$deDupeString$2.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Solutions$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Solutions$.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Solutions.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Solutions.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/Summary.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/Summary.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/TreeNode$.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/TreeNode$.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/TreeNode.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/TreeNode.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/TreeOperations.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/TreeOperations.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/WordLadder.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/WordLadder.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/codeforces/MyScanner.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/codeforces/MyScanner.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/codeforces/P112A.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/codeforces/P112A.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/codeforces/P160A.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/codeforces/P160A.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/codeforces/P253B.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/codeforces/P253B.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/codeforces/P327A.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/codeforces/P327A.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/classes/codeforces/P580A.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/classes/codeforces/P580A.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/Anagramtest$$anonfun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/Anagramtest$$anonfun$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/Anagramtest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/Anagramtest.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/IntervalTest$$anonfun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/IntervalTest$$anonfun$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/IntervalTest$$anonfun$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/IntervalTest$$anonfun$2.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/IntervalTest$$anonfun$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/IntervalTest$$anonfun$3.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/IntervalTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/IntervalTest.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/InterviewTest$$anonfun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/InterviewTest$$anonfun$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/InterviewTest$$anonfun$randomArray$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/InterviewTest$$anonfun$randomArray$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/InterviewTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/InterviewTest.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P112ATest$$anonfun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P112ATest$$anonfun$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P112ATest$$anonfun$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P112ATest$$anonfun$2.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P112ATest$$anonfun$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P112ATest$$anonfun$3.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P112ATest$$anonfun$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P112ATest$$anonfun$4.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P112ATest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P112ATest.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$2.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$2.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$3.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$3.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$4.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1$$anonfun$apply$mcV$sp$4.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P160ATest$$anonfun$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P160ATest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P160ATest.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P327ATest$$anonfun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P327ATest$$anonfun$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P327ATest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P327ATest.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P580ATest$$anonfun$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P580ATest$$anonfun$1.class -------------------------------------------------------------------------------- /practice/target/scala-2.11/test-classes/P580ATest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/scala-2.11/test-classes/P580ATest.class -------------------------------------------------------------------------------- /practice/target/streams/$global/$global/$global/streams/out: -------------------------------------------------------------------------------- 1 | [debug] Other repositories: 2 | [debug] Default repositories: 3 | [debug] Other repositories: 4 | [debug] Default repositories: 5 | -------------------------------------------------------------------------------- /practice/target/streams/$global/dependencyPositions/$global/streams/update_cache_2.11/input_dsp: -------------------------------------------------------------------------------- 1 | org.scala-lang scala-library2.11.7 org.scalatestscalatest_2.112.2.4test -------------------------------------------------------------------------------- /practice/target/streams/$global/dependencyPositions/$global/streams/update_cache_2.11/output_dsp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/streams/$global/dependencyPositions/$global/streams/update_cache_2.11/output_dsp -------------------------------------------------------------------------------- /practice/target/streams/$global/ivyConfiguration/$global/streams/out: -------------------------------------------------------------------------------- 1 | [debug] Other repositories: 2 | [debug] Default repositories: 3 | [debug] Using inline dependencies specified in Scala. 4 | -------------------------------------------------------------------------------- /practice/target/streams/$global/ivySbt/$global/streams/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/streams/$global/ivySbt/$global/streams/out -------------------------------------------------------------------------------- /practice/target/streams/$global/projectDescriptors/$global/streams/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/streams/$global/projectDescriptors/$global/streams/out -------------------------------------------------------------------------------- /practice/target/streams/$global/update/$global/streams/update_cache_2.11/inputs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/streams/$global/update/$global/streams/update_cache_2.11/inputs -------------------------------------------------------------------------------- /practice/target/streams/$global/update/$global/streams/update_cache_2.11/output: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/streams/$global/update/$global/streams/update_cache_2.11/output -------------------------------------------------------------------------------- /practice/target/streams/compile/compile/$global/streams/out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/practice/target/streams/compile/compile/$global/streams/out -------------------------------------------------------------------------------- /practice/target/streams/compile/compileIncremental/$global/streams/export: -------------------------------------------------------------------------------- 1 | scalac -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home/jre/classes:/Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar -classpath /Users/karthik/Development/algo/practice/target/scala-2.11/classes /Users/karthik/Development/algo/practice/src/main/scala/Judge.scala /Users/karthik/Development/algo/practice/src/main/scala/Solutions.scala /Users/karthik/Development/algo/practice/src/main/scala/Tree.scala 2 | -------------------------------------------------------------------------------- /practice/target/streams/compile/dependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar 2 | -------------------------------------------------------------------------------- /practice/target/streams/compile/externalDependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar 2 | -------------------------------------------------------------------------------- /practice/target/streams/compile/internalDependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/target/streams/compile/managedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar 2 | -------------------------------------------------------------------------------- /practice/target/streams/compile/unmanagedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/target/streams/compile/unmanagedJars/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/target/streams/runtime/externalDependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar 2 | -------------------------------------------------------------------------------- /practice/target/streams/runtime/managedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar 2 | -------------------------------------------------------------------------------- /practice/target/streams/runtime/unmanagedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/target/streams/runtime/unmanagedJars/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/target/streams/test/externalDependencyClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar:/Users/karthik/.ivy2/cache/org.scalatest/scalatest_2.11/bundles/scalatest_2.11-2.2.4.jar:/Users/karthik/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.2.jar:/Users/karthik/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.2.jar 2 | -------------------------------------------------------------------------------- /practice/target/streams/test/managedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | /Users/karthik/.ivy2/cache/org.scala-lang/scala-library/jars/scala-library-2.11.7.jar:/Users/karthik/.ivy2/cache/org.scalatest/scalatest_2.11/bundles/scalatest_2.11-2.2.4.jar:/Users/karthik/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.2.jar:/Users/karthik/.ivy2/cache/org.scala-lang.modules/scala-xml_2.11/bundles/scala-xml_2.11-1.0.2.jar 2 | -------------------------------------------------------------------------------- /practice/target/streams/test/unmanagedClasspath/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /practice/target/streams/test/unmanagedJars/$global/streams/export: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /preOrderInrderbuild.py: -------------------------------------------------------------------------------- 1 | class Node: 2 | def __init__(self,val): 3 | self.left = None 4 | self.right = None 5 | self.val = val 6 | 7 | class Solution: 8 | 9 | def __init__(self): 10 | pass 11 | 12 | def buildTree(self,preOrder,inOrder): 13 | if inOrder == "": 14 | return None,preOrder 15 | else: 16 | for i in range(len(inOrder)): 17 | if inOrder[i] == preOrder[0]: 18 | break 19 | 20 | left = inOrder[0:i] 21 | right = inOrder[i+1:] 22 | node = Node(preOrder[0]) 23 | preOrder = preOrder[1:] 24 | node.left,preOrder = self.buildTree(preOrder,left) 25 | node.right,preOrder = self.buildTree(preOrder,right) 26 | 27 | return node,preOrder 28 | 29 | def inOrder(self,root): 30 | if root == None: 31 | return 32 | else: 33 | self.inOrder(root.left) 34 | print root.val, 35 | self.inOrder(root.right) 36 | def main(): 37 | s = Solution() 38 | node,preOrder = s.buildTree("asd","sad") 39 | s.inOrder(node) 40 | print 41 | 42 | node,preOrder = s.buildTree("asd","dsa") 43 | s.inOrder(node) 44 | print 45 | 46 | node,preOrder = s.buildTree("asd","asd") 47 | s.inOrder(node) 48 | print 49 | 50 | 51 | node,preOrder = s.buildTree("dbac","abcd") 52 | s.inOrder(node) 53 | print 54 | if __name__ == '__main__': 55 | main() 56 | 57 | 58 | 59 | # so we find the index at whicg D occurs 60 | # then anyting to left of it becomes the left subtree - so buidTree(C,CE) 61 | 62 | # then buildTree(None,E): 63 | -------------------------------------------------------------------------------- /random: -------------------------------------------------------------------------------- 1 | recurrence 2 | 3 | 4 | F(Source, Destination, n) = Sum(F(neigh(source), destinatin , n-1)) 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /random~: -------------------------------------------------------------------------------- 1 | recurrence 2 | 3 | 4 | F(Source, Destination, n) = Sum(F(neigh(source), destinatin , n-1)) 5 | 6 | 7 | -------------------------------------------------------------------------------- /reverseWords.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | 3 | def reverseLine(self,str_): 4 | start = 0 5 | end = 0 6 | 7 | while end < len(str_) and str_[end] == ' ': 8 | end += 1 9 | start = end 10 | 11 | while end < len(str_): 12 | if str_[end] == ' ': 13 | self.reverseWord(str_, start, end-1) 14 | while end < len(str_) and str_[end] == ' ': 15 | end += 1 16 | start = end 17 | else: 18 | end += 1 19 | 20 | if start != end: 21 | self.reverseWord(str_, start, end-1) 22 | 23 | self.reverseWord(str_, 0, len(str_)-1) 24 | return ''.join(str_) 25 | 26 | 27 | def reverseWord(self,str_,start,end): 28 | 29 | while start < end: 30 | self.swap(str_,start,end) 31 | start += 1 32 | end -= 1 33 | 34 | def swap(self,str_,i,j): 35 | temp = str_[i] 36 | str_[i] = str_[j] 37 | str_[j] = temp 38 | 39 | def main(): 40 | s = Solution() 41 | print s.reverseLine(list(" ")) 42 | print s.reverseLine(list("")) 43 | print s.reverseLine(list(" ")) 44 | print s.reverseLine(list("a ")) 45 | print s.reverseLine(list("Karthik is aaaaannnnddd iuj")) 46 | print s.reverseLine(list(" ")) 47 | 48 | if __name__ == '__main__': 49 | main() -------------------------------------------------------------------------------- /rotate.py: -------------------------------------------------------------------------------- 1 | def rotate(a,k): 2 | if len(a) % 2 == 0 and len(a)/2 == k: 3 | for i in range(0,len(a)/2): 4 | swap1(a,i,(i+k) % len(a)) 5 | 6 | else: 7 | rounds = 0 8 | i = 0 9 | temp = a[i] 10 | 11 | while rounds < len(a): 12 | temp = swap2(temp,a,(i+k)%len(a)) 13 | rounds += 1 14 | i = (i+k) % len(a) 15 | 16 | return a 17 | 18 | def swap1(a,i,j): 19 | temp = a[i] 20 | a[i] = a[j] 21 | a[j] = temp 22 | 23 | def swap2(var,a,index): 24 | temp = var 25 | var = a[index] 26 | a[index] = temp 27 | 28 | return var 29 | 30 | 31 | 32 | 33 | def main(): 34 | print rotate([1,2,3,4],2) 35 | print rotate([1,2],1) 36 | print rotate([1,2,3,4,5,7],3) 37 | print rotate([1,2,5,7,8,9,10],4) 38 | 39 | if __name__ == '__main__': 40 | main() -------------------------------------------------------------------------------- /someNeighbor.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # @param board, a list of lists of 1 length string 3 | # @param word, a string 4 | # @return a boolean 5 | # i - dx 6 | # j - dy 7 | neighbor = {} 8 | 9 | def exist(self, board, word): 10 | dx = [0,0,-1,1] 11 | dy = [-1,1,0,0] 12 | 13 | for i,word in enumerate(board): 14 | for j,char in enumerate(word): 15 | print char,word 16 | if char not in Solution.neighbor: 17 | Solution.neighbor[char] = set() 18 | 19 | for k in range(len(dx)): 20 | if i+dx[k] >=0 and i+dx[k] < len(board) and j+dy[k] >=0 and j + dy[k] < len(word): 21 | Solution.neighbor[char].add(board[i+dx[k]][j+dy[k]]) 22 | 23 | if len(word) == 0: 24 | print ""== word 25 | 26 | 27 | searchChar = word[0] 28 | 29 | if searchChar in Solution.neighbor: 30 | li = Solution.neighbor[searchChar] 31 | 32 | for char in range(1,len(word)): 33 | if char not in li: 34 | return False 35 | else: 36 | li = Solution.neighbor[char] 37 | 38 | return True 39 | else: 40 | return False 41 | 42 | 43 | def main(): 44 | s = Solution() 45 | print s.exist(["ABCE","SFCS","ADEE"], "ASAD") 46 | print Solution.neighbor 47 | 48 | if __name__ == '__main__': 49 | main() 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /stack_Max.py: -------------------------------------------------------------------------------- 1 | class Max_Stack: 2 | stack = [] 3 | max_stack = [] 4 | 5 | def push(self,item): 6 | if len(self.stack) == 0: 7 | self.max_stack.append(item) 8 | elif item > self.max_stack[-1]: 9 | self.max_stack.append(item) 10 | else: 11 | self.max_stack.append(self.max_()) 12 | 13 | self.stack.append(item) 14 | 15 | def pop(self): 16 | self.stack.pop() 17 | self.max_stack.pop() 18 | 19 | def max_(self): 20 | return self.max_stack[-1] 21 | 22 | def main(): 23 | s = Max_Stack() 24 | s.push(1) 25 | s.push(2) 26 | s.push(5) 27 | s.push(9) 28 | s.push(-1) 29 | s.push(-1) 30 | s.push(-1) 31 | s.push(100) 32 | print s.max_() 33 | s.pop() 34 | print s.max_() 35 | if __name__ == '__main__': 36 | main() -------------------------------------------------------------------------------- /subsets.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # @param S, a list of integer 3 | # @return a list of lists of integer 4 | finalAns = [] 5 | def subsets(self, S): 6 | S = sorted(S) 7 | self.subsetsHelper(S,[],None,0) 8 | temp = Solution.finalAns 9 | Solution.finalAns = [] 10 | return temp 11 | 12 | def subsetsHelper(self,S,ans,recentIncluded,index): 13 | if index == len(S): 14 | ans = [x for x in ans] 15 | Solution.finalAns.append(ans) 16 | else: 17 | if index >= 1 and S[index] == S[index-1]: 18 | if recentIncluded == S[index]: 19 | ans.append(S[index]) 20 | else: 21 | pass 22 | else: 23 | ans.append(S[index]) 24 | recentIncluded = S[index] 25 | 26 | self.subsetsHelper(S,ans,recentIncluded,index+1) 27 | ans.pop() 28 | if len(ans) > 0: 29 | recentIncluded = ans[-1] 30 | else: 31 | recentIncluded = None 32 | self.subsetsHelper(S,ans,recentIncluded,index+1) 33 | 34 | 35 | 36 | def main(): 37 | s = Solution() 38 | print s.subsets([1,2,2]) 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /twStackQ.py: -------------------------------------------------------------------------------- 1 | class Queue: 2 | 3 | def __init__(self): 4 | self.s1 = [] 5 | self.s2 = [] 6 | 7 | def push(self,item): 8 | self.s1.append(item) 9 | 10 | def pop(self): 11 | if len(self.s2) != 0: 12 | return self.s2.pop() 13 | else: 14 | while len(self.s1) != 0: 15 | self.s2.append(self.s1.pop()) 16 | 17 | return self.s2.pop() 18 | 19 | def size(self): 20 | return len(self.s1) + len(self.s2) 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /uniquepaths (Case Conflict).py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | cache = [] 3 | 4 | def uniquePaths(self,m,n): 5 | for i in range(m): 6 | Solution.cache.append([-1]*n) 7 | 8 | for j in range(n): 9 | Solution.cache[0][j] = 1 10 | 11 | for i in range(m): 12 | Solution.cache[i][0] = 1 13 | 14 | for i in range(1,m): 15 | for j in range(1,n): 16 | Solution.cache[i][j] = Solution.cache[i-1][j] + Solution.cache[i][j-1] 17 | 18 | ans = Solution.cache[m-1][n-1] 19 | Solution.cache = [] 20 | return ans 21 | 22 | def main(): 23 | s = Solution() 24 | print s.uniquePaths(10,1) 25 | 26 | 27 | if __name__ == '__main__': 28 | main() -------------------------------------------------------------------------------- /uniquepaths.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | # @return an integer 3 | cache = [[]] 4 | def uniquePaths(self, m, n): 5 | for i in range(m): 6 | Solution.cache.append([-1]*n) 7 | 8 | for i in range(n): 9 | Solution.cache[0][i] = 1 10 | 11 | for i in range(m): 12 | Solution.cache[i][0] = 1 13 | 14 | for i in range(1,m): 15 | for j in range(1,n): 16 | Solution.cache[i][j] = Solution.cache[i-1][j] + Solution.cache[i][j-1] 17 | 18 | return Solution.cache[m-1][n-1] 19 | 20 | def main(): 21 | pass 22 | if __name__ == '__main__': 23 | main() -------------------------------------------------------------------------------- /validBST.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | # Definition for a binary tree node 4 | class TreeNode: 5 | def __init__(self, x): 6 | self.val = x 7 | self.left = None 8 | self.right = None 9 | 10 | class Solution: 11 | # @param root, a tree node 12 | # @return a boolean 13 | # for every subtree u have a >= and a less = 14 | # every node must be within this 15 | def isValidBST(self, root): 16 | return self.isValidBSTHelper(root,-sys.maxint-1,sys.maxint) 17 | 18 | def isValidBSTHelper(self,root,min_,max_): 19 | if root == None: 20 | return True 21 | else: 22 | if root.val > min_ and root.val < max_: 23 | self.isValidBSTHelper(root.left,min_,root.val) and self.isValidBSTHelper(root.right,root.val,max_) 24 | else: 25 | return False -------------------------------------------------------------------------------- /vijayQ.py: -------------------------------------------------------------------------------- 1 | class Solution: 2 | 3 | def generateString(self,str_,index): 4 | if index == len(str_): 5 | print str_ 6 | return 7 | 8 | elif str_[index] == '$': 9 | str_ = str_[0:index] + '0' + str_[index+1:] 10 | self.generateString(str_, index+1) 11 | str_ = str_[0:index] + '1' + str_[index+1:] 12 | self.generateString(str_, index+1) 13 | else: 14 | self.generateString(str_, index+1) 15 | 16 | 17 | 18 | def main(): 19 | s = Solution() 20 | s.generateString("$ab$c$", 0) 21 | 22 | if __name__ == '__main__': 23 | main() -------------------------------------------------------------------------------- /vineetString.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/treadstone90/algo/73379e3adb0fb3009a4d17f36676da260601de3c/vineetString.py -------------------------------------------------------------------------------- /wordbreaking.py: -------------------------------------------------------------------------------- 1 | # given a string with just some set fo words we need to determine 2 | # whether there exists a valid brealing of the words into 3 | # some words in the dictionary 4 | # and if so return. Else return a -1 5 | 6 | class Solution: 7 | 8 | 9 | def main(): 10 | pass 11 | if __name__ == '__main__': 12 | main() --------------------------------------------------------------------------------