├── .gitignore ├── README.md ├── TEXQuotes.in ├── in.txt └── src ├── general ├── Endofile.java ├── InputOutput.java ├── OlympicArray.java └── TestMUM.java ├── hackerrank ├── ArrayManipulation.java ├── ArraysLeftRotation.java ├── BestDivisor.java ├── BetweenTwoSets.java ├── CountTriplets.java ├── DesignerPDFViewer.java ├── DivisibleSumPairs.java ├── FrequencyQueries.java ├── HashTablesRansomNote.java ├── Hashset.java ├── MakingAnagrams.java ├── MinimumSwaps2.java ├── NewYearChaos.java ├── SherlockValid.java ├── SherlockandAnagrams.java ├── SockMerchant.java ├── SpecialPalindromeAgain.java ├── Twin.java ├── TwoDArrayDS.java └── UtopianTree.java ├── queue └── PriorityCustomer.java ├── sortSearch ├── BubbleSort.java ├── ExchangeSort.java ├── InsertionSort.java ├── QuickSort.java ├── SelectionSort.java └── ShellSort.java └── uva ├── AutomaticAnswer.java ├── Bafana.java ├── BeatSpread.java ├── BigChocolate.java ├── BlowingFuses.java ├── BoxBricks.java ├── Brainfuck.java ├── BurgerTime.java ├── ClockHands.java ├── CombinationLock.java ├── CostCutting.java ├── DigitCounting.java ├── DivisionNlogonia.java ├── Egypt.java ├── EmoogleBalance.java ├── F91.java ├── FlipSort.java ├── FormingQuizTeams.java ├── FourthPoint.java ├── GCD.java ├── GoogleFeelingLucky.java ├── HappyBirthday.java ├── HelloWorld.java ├── JumpingMario.java ├── LaserSculpture.java ├── LeapYear.java ├── LoveCalculator.java ├── P12578.java ├── Parking.java ├── PeterSmokes.java ├── PowerCryptography.java ├── Prerequisites.java ├── PrimaryArithmetic.java ├── RequestProposal.java ├── ReverseAdd.java ├── RobotInstructions.java ├── SMSTyping.java ├── SaveSetu.java ├── ScheduleMarriedMan.java ├── SearchingNessy.java ├── SecretResearch.java ├── SquareNumbers.java ├── SubPrime.java ├── SummingDigits.java ├── SwallowingGround.java ├── TEXQuotes.java ├── TariffPlan.java ├── Ternary.java ├── The3n1problem.java ├── TheSnail.java ├── TrainSwapping.java ├── TrainTracks.java ├── TroublePentagon.java ├── WERTYU.java ├── WhatMedian.java └── ZerosOnes.java /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /bin/ 3 | .settings/ 4 | .classpath 5 | .project 6 | .idea/ 7 | 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Algorithms-Java 2 | 3 | Solutions to problems on algorithms from UVa Online Judge(ACM-ICPC Live Archive), hackerrank, Leetcode.com 4 | 5 | Using: Arrays, Hash Table, LinkedList, Binary Search, Dynamic Programming, Stack , Heap, reedy, Sort, Tree 6 | DFS, BFS, Graph, Binary Search Tree, Recursion, Memoization, Queue ,Map, etc. 7 | 8 | My current statistic 9 | - [UVa Online Judge - ACM-ICPC Live Archive](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=14&page=show_authorstats&userid=61430) 10 | - [Leetcode](https://leetcode.com/edyluisrey/) 11 | 12 | | # | problems | Solutions | From |Tags, Notes 13 | | ------|:---------------------------------------------------- |:------------:| --------------------------:|--------------:| 14 | |1 | [Google is Feeling Lucky](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3166) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/GoogleFeelingLucky.java) | Uva-ACM-ICPC | Array | 15 | |2 |[Zeros and Ones](https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1265) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/ZerosOnes.java) | Uva-ACM-ICPC |String | 16 | | 3| [What is the Median?](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1048) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/WhatMedian.java) | Uva-ACM-ICPC |ArrayList| 17 | |4| [P12578](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4023) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/P12578.java) | Uva-ACM-ICPC | Math| 18 | | 5| [A Special "Happy Birthday" Song!!!](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3999) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/HappyBirthday.java) | Uva-ACM-ICPC |Array | 19 | |6 | [Robot Instructions](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3947) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/RobotInstructions.java) | Uva-ACM-ICPC |Array | 20 | |7|[Save Setu](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3834) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/SaveSetu.java) | Uva-ACM-ICPC | | 21 | |8|[Emoogle Balance](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3431) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/EmoogleBalance.java) | Uva-ACM-ICPC | | 22 | |9| [Tariff Plan](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3309) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/TariffPlan.java) | Uva-ACM-ICPC | 23 | |10| [Schedule of a Married Man](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3288) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/ScheduleMarriedMan.java) | Uva-ACM-ICPC | 24 | |11| [Brainfuck](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3107) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/Brainfuck.java) | Uva-ACM-ICPC | 25 | |12| [Egypt](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2954) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/Egypt.java) | Uva-ACM-ICPC | 26 | |13| [Bafana Bafana](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2905) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/Bafana.java) | Uva-ACM-ICPC | 27 | |14| [Jumping Mario](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2864) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/JumpingMario.java) | Uva-ACM-ICPC | 28 | |15| [Cost Cutting](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2827) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/CostCutting.java) | Uva-ACM-ICPC | 29 | |16| [Laser Sculpture](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2730) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/LaserSculpture.java) | Uva-ACM-ICPC | 30 | |17| [Sub-prime](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2726) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/SubPrime.java) | Uva-ACM-ICPC | 31 | |18| [Burger Time?](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2708) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/BurgerTime.java) | Uva-ACM-ICPC | 32 | |19| [Hello World!](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2683) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/HelloWorld.java) | Uva-ACM-ICPC | 33 | |20| [Train Tracks](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2633) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/TrainTracks.java) | Uva-ACM-ICPC | 34 | |21| [Automatic Answer](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2542) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/AutomaticAnswer.java) | Uva-ACM-ICPC | 35 | |22| [SMS Typing](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2525) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/SMSTyping.java) | Uva-ACM-ICPC | 36 | |23| [Division of Nlogonia](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2493) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/DivisionNlogonia.java) | Uva-ACM-ICPC | 37 | |24| [Square Numbers](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2456) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/SquareNumbers.java) | Uva-ACM-ICPC | 38 | |25| [GCD](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2412) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/GCD.java) | Uva-ACM-ICPC | 39 | |26| [Parking](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2349) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/Parking.java) | Uva-ACM-ICPC | 40 | |27| [Summing Digits](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2307) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/SummingDigits.java) | Uva-ACM-ICPC | 41 | |28| [Ternary](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2126) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/Ternary.java) | Uva-ACM-ICPC | 42 | |29| [Searching for Nessy](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1985) | [Java](https://github.com/edyluisrey/Algorithms-Java/blob/master/src/uva/SearchingNessy.java) | Uva-ACM-ICPC | 43 | |30| [Big Chocolate](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1911) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/BigChocolate.java) | Uva-ACM-ICPC | 44 | |31| [The Swallowing Ground](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1904) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/SwallowingGround.java) | Uva-ACM-ICPC | 45 | |32| [Prerequisites?](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1860) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/Prerequisites.java) | Uva-ACM-ICPC | 46 | |33| [Beat the Spread!](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1753) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/BeatSpread.java) | Uva-ACM-ICPC | 47 | |34| [Combination Lock](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1491) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/CombinationLock.java) | Uva-ACM-ICPC | 48 | |35| [Love Calculator](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1365) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/LoveCalculator.java) | Uva-ACM-ICPC | 49 | |36| [Peter's Smokes](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1287) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/PeterSmokes.java) | Uva-ACM-ICPC | 50 | |37| [Flip Sort](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1268) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/FlipSort.java) | Uva-ACM-ICPC | 51 | |38| [rouble with a Pentagon](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1227) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/TroublePentagon.java) | Uva-ACM-ICPC | 52 | |39| [Fourth Point !!](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1183) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/FourthPoint.java) | Uva-ACM-ICPC | 53 | |40| [Request for Proposal](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1082) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/RequestProposal.java) | Uva-ACM-ICPC | 54 | |41| [What is the Median?](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1048) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/WhatMedian.java) | Uva-ACM-ICPC | 55 | |42| [WERTYU](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1023) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/WERTYU.java) | Uva-ACM-ICPC | 56 | |43| [Primary Arithmetic](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=976) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/PrimaryArithmetic.java) | Uva-ACM-ICPC | 57 | |44| [Reverse and Add](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=959) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/ReverseAdd.java) | Uva-ACM-ICPC | 58 | |45| [Digit Counting](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3666) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/DigitCounting.java) | Uva-ACM-ICPC | 59 | |46| [Blowing Fuses](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=602) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/BlowingFuses.java) | Uva-ACM-ICPC | 60 | |47| [Secret Research](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=562) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/SecretResearch.java) | Uva-ACM-ICPC | 61 | |48| [Box of Bricks](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=532) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/BoxBricks.java) | Uva-ACM-ICPC | 62 | |49| [Clock Hands](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=520) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/ClockHands.java) | Uva-ACM-ICPC | 63 | |50| [The Snail](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=514) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/TheSnail.java) | Uva-ACM-ICPC | 64 | |51| [Train Swapping](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=235) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/TrainSwapping.java) | Uva-ACM-ICPC | 65 | |52| [TEX Quotes](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=208) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/TEXQuotes.java) | Uva-ACM-ICPC | 66 | |53| [Power of Cryptography](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=49) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/PowerCryptography.java) | Uva-ACM-ICPC | 67 | |54| [The 3n + 1 problem](https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/uva/The3n1problem.java) | Uva-ACM-ICPC | 68 | |55| [Between Two Sets](https://www.hackerrank.com/challenges/between-two-sets) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/BetweenTwoSets.java) | Hackerrank.com | 69 | |56| [Divisible Sum Pairs](https://www.hackerrank.com/challenges/divisible-sum-pairs) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/DivisibleSumPairs.java) | Hackerrank.com | 70 | |57| [Designer PDF Viewer](https://www.hackerrank.com/challenges/designer-pdf-viewer) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/DesignerPDFViewer.java) | Hackerrank.com | 71 | |58| [Sock Merchant](https://www.hackerrank.com/challenges/sock-merchant) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/SockMerchant.java) | Hackerrank.com | 72 | |59| [Utopian Tree](https://www.hackerrank.com/challenges/utopian-tree) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/UtopianTree.java) | Hackerrank.com | 73 | |60| [Twins](https://www.hackerrank.com/contests/w26/challenges/twins) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/Twin.java) | Hackerrank.com | 74 | |61| [Add Two Numbers](https://leetcode.com/problems/add-two-numbers/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/AddTwoNumbers.java) | LeetCode Online Judge | 75 | |62| [Longest Substring Without Repeating Characters](https://leetcode.com/problems/longest-substring-without-repeating-characters/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/LongestSubstring.java) | LeetCode Online Judge | 76 | |63| [ZigZag Conversion](https://leetcode.com/problems/zigzag-conversion/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ZigZagConversion.java) | LeetCode Online Judge | 77 | |64| [Reverse Integer](https://leetcode.com/problems/reverse-integer/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ReverseInteger.java) | LeetCode Online Judge | 78 | |65| [String to Integer (atoi)](https://leetcode.com/problems/string-to-integer-atoi/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/StringInteger.java) | LeetCode Online Judge | 79 | |66| [Palindrome Number](https://leetcode.com/problems/palindrome-number/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/PalindromeNumber.java) | LeetCode Online Judge | 80 | |67| [Longest Palindromic Substring](https://leetcode.com/problems/longest-palindromic-substring/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/LongestPalindromicSubstring.java) | LeetCode Online Judge | 81 | |68| [Roman to Integer](https://leetcode.com/problems/roman-to-integer/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/RomanInteger.java) | LeetCode Online Judge | 82 | |69| [Longest Common Prefix](https://leetcode.com/problems/longest-common-prefix/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/LongestCommonPrefix.java) | LeetCode Online Judge | 83 | |70| [Word Ladder](https://leetcode.com/problems/word-ladder/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/WordLadder.java) | LeetCode Online Judge |Queue, BFS | 84 | |71| [Valid Parentheses](https://leetcode.com/problems/valid-parentheses/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ValidParentheses.java) | LeetCode Online Judge |Stack | 85 | |72| [Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MergeTwoSortedLists.java) | LeetCode Online Judge |LinkedList | 86 | |73| [Container With Most Water](https://leetcode.com/problems/container-with-most-water/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ContainerWithMostWater.java) | LeetCode Online Judge |Array, Math | 87 | |74| [Remove Duplicates from Sorted Array](https://leetcode.com/problems/remove-duplicates-from-sorted-array/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/RemoveDuplicatesfromSortedArray.java) | LeetCode Online Judge | 88 | |75| [Remove Element](https://leetcode.com/problems/remove-element/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/RemoveElement.java) | LeetCode Online Judge | Array | 89 | |76| [Same Tree](https://leetcode.com/problems/same-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SameTree.java) | LeetCode Online Judge | Tree | 90 | |77| [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SymmetricTree.java) | LeetCode Online Judge | Tree | 91 | |78| [3Sum Closest](https://leetcode.com/problems/3sum-closest/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/TreeSumClosest.java) | LeetCode Online Judge |Arrays, Math | 92 | |79| [Sort Characters By Frequency](https://leetcode.com/problems/sort-characters-by-frequency/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SortCharactersByFrequency.java) | LeetCode Online Judge | | 93 | |80| [Kill Process](https://leetcode.com/problems/kill-process/#/description) | [Java]() | LeetCode Online Judge | | 94 | |81| [Isomorphic Strings](https://leetcode.com/problems/isomorphic-strings/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/IsomorphicStrings.java) | LeetCode Online Judge | 95 | |82| [Intersection of Two Arrays](https://leetcode.com/problems/intersection-of-two-arrays/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/IntersectionTwoArrays.java) | LeetCode Online Judge | 96 | |83| [Palindrome Linked List](https://leetcode.com/problems/palindrome-linked-list/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/PalindromeLinkedList.java) | LeetCode Online Judge | 97 | |84| [Minimum Absolute Difference in BST](https://leetcode.com/problems/minimum-absolute-difference-in-bst/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MinimumAbsoluteDifferenceBST.java) | LeetCode Online Judge | 98 | |85| [Min Stack](https://leetcode.com/problems/min-stack/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MinStack.java) | LeetCode Online Judge | 99 | |86| [Implement Stack using Queues](https://leetcode.com/problems/implement-stack-using-queues/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ImplementStackQueues.java) | LeetCode Online Judge | 100 | |87| [Search Insert Position](https://leetcode.com/problems/search-insert-position/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SearchInsertPosition.java) | LeetCode Online Judge | 101 | |88| [Sum of Left Leaves](https://leetcode.com/problems/sum-of-left-leaves/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SumLeftLeavesTree.java) | LeetCode Online Judge | 102 | |89| [Maximum Depth of Binary Tree](https://leetcode.com/problems/maximum-depth-of-binary-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MaximumDepthBinaryTree.java) | LeetCode Online Judge | 103 | |90| [Next Greater Element I](https://leetcode.com/problems/next-greater-element-i/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/NextGreaterElementI.java) | LeetCode Online Judge | 104 | |91| [Implement Queue using Stacks](https://leetcode.com/problems/implement-queue-using-stacks/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ImplementQueueusingStacks.java) | LeetCode Online Judge | 105 | |92| [Rotate Array]( https://leetcode.com/problems/reshape-the-matrix/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ReshapetheMatrix.java) | LeetCode Online Judge | 106 | |93| [Rotate Array](https://leetcode.com/problems/rotate-array/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/RotateArray.java) | LeetCode Online Judge | 107 | |94| [Best Time to Buy and Sell Stock](https://leetcode.com/problems/best-time-to-buy-and-sell-stock/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/BestTimeBuySellStock.java) | LeetCode Online Judge |Dynamic P.| 108 | |95| [Simplify Path](https://leetcode.com/problems/simplify-path/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SimplifyPath.java) | LeetCode Online Judge | 109 | |96| [Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/EvaluateReversePolishNotation.java) | LeetCode Online Judge | 110 | |97| [Contains Duplicate](https://leetcode.com/problems/contains-duplicate/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ContainsDuplicate.java) | LeetCode Online Judge | 111 | |98| [Decode String](https://leetcode.com/problems/decode-string/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/DecodeString.java) | LeetCode Online Judge | 112 | |99| [Search a 2D Matrix](https://leetcode.com/problems/search-a-2d-matrix/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/Search2DMatrix.java) | LeetCode Online Judge | 113 | |100| [Range Sum Query 2D - Immutable](https://leetcode.com/problems/range-sum-query-2d-immutable/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/NumMatrix.java) | LeetCode Online Judge |Dynamic P.| 114 | |101| [Valid Anagram](https://leetcode.com/problems/valid-anagram/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ValidAnagram.java) | LeetCode Online Judge | 115 | |102| [Longest Word in Dictionary through Deleting](https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/LongestWordDictionarythroughDeleting.java) | LeetCode Online Judge | 116 | |103| [Sort List](https://leetcode.com/problems/sort-list/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SortListTest.java) | LeetCode Online Judge | 117 | |104| [Sort Colors](https://leetcode.com/problems/sort-colors/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SortColors.java) | LeetCode Online Judge | 118 | |105| [Maximum Subarray](https://leetcode.com/problems/maximum-subarray/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MaximumSubarray.java) | LeetCode Online Judge |Dynamic P.| 119 | |106| [Range Sum Query - Immutable](https://leetcode.com/problems/range-sum-query-immutable/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/NumArray.java) | LeetCode Online Judge |Dynamic P.| 120 | |107| [House Robber](https://leetcode.com/problems/house-robber/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/HouseRobber.java) | LeetCode Online Judge |Dynamic P.| 121 | |108| [Single Number](https://leetcode.com/problems/single-number/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SingleNumber.java) | LeetCode Online Judge | 122 | |109| [Happy Number](https://leetcode.com/problems/happy-number/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/HappyNumber.java) | LeetCode Online Judge | 123 | |110| [Count Primes](https://leetcode.com/problems/count-primes/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/CountPrimes.java) | LeetCode Online Judge | 124 | |111| [Word Pattern](https://leetcode.com/problems/word-pattern/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/WordPattern.java) | LeetCode Online Judge |Hash Table | 125 | |112| [Keyboard Row](https://leetcode.com/problems/keyboard-row/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/KeyboardRow.java) | LeetCode Online Judge |HashTable| 126 | |113| [Longest Harmonious Subsequence](https://leetcode.com/problems/longest-harmonious-subsequence/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/LongestHarmoniousSubsequence.java) | LeetCode Online Judge |HashMap | 127 | |114| [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/BinaryTreeInorderTraversal.java) | LeetCode Online Judge | Tree | 128 | |115| [Clone Graph](https://leetcode.com/problems/clone-graph/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/CloneGraph.java) | LeetCode Online Judge |Graph,BFS| 129 | |116| [Merge Two Binary Trees](https://leetcode.com/problems/merge-two-binary-trees/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MergeTwoBinaryTrees.java) | LeetCode Online Judge |Tree | 130 | |117| [Subtree of Another Tree](https://leetcode.com/problems/subtree-of-another-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SubtreeAnotherTree.java) | LeetCode Online Judge |Tree | 131 | |118| [Binary Tree Tilt](https://leetcode.com/problems/binary-tree-tilt/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/BinaryTreeTilt.java) | LeetCode Online Judge |Tree | 132 | |119| [Diameter of Binary Tree](https://leetcode.com/problems/diameter-of-binary-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/DiameterBinaryTree.java) | LeetCode Online Judge |Tree, DFS | 133 | |120| [Path Sum](https://leetcode.com/problems/path-sum/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/PathSum.java) | LeetCode Online Judge |Tree | 134 | |121| [Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/RemoveDuplicatesfromSortedList.java) | LeetCode Online Judge |LinkedList | 135 | |122| [Rotate List](https://leetcode.com/problems/rotate-list/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/RotateList.java) | LeetCode Online Judge |LinkedList | 136 | |123| [Reverse Linked List](https://leetcode.com/problems/reverse-linked-list/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ReverseLinkedList.java) | LeetCode Online Judge | | 137 | |124| [Guess Number Higher or Lower](https://leetcode.com/problems/guess-number-higher-or-lower/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/GuessNumberHigherorLower.java) | LeetCode Online Judge |BS | 138 | |125| [Two Sum II - Input array is sorted](https://leetcode.com/problems/two-sum-ii-input-array-is-sorted/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/TwoSumIInputarrayissorted.java) | LeetCode Online Judge |BS | 139 | |126| [Beautiful Arrangement](https://leetcode.com/problems/beautiful-arrangement/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/BeautifulArrangement.java) | LeetCode Online Judge |Backtracking | 140 | |127| [Delete Operation for Two Strings](https://leetcode.com/problems/delete-operation-for-two-strings/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/DeleteOperationforTwoStrings.java) | LeetCode Online Judge |DP | 141 | |128| [Construct String from Binary Tree](https://leetcode.com/problems/construct-string-from-binary-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ConstructStringfromBinaryTree.java) | LeetCode Online Judge |Tree | 142 | |129| [Optimal Division](https://leetcode.com/problems/optimal-division/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/OptimalDivision.java) | LeetCode Online Judge |String | 143 | |130| [Count and Say](https://leetcode.com/problems/count-and-say/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/CountandSay.java) | LeetCode Online Judge | | 144 | |131| [Merge Sorted Array](https://leetcode.com/problems/merge-sorted-array/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MergeSortedArray.java) | LeetCode Online Judge | | 145 | |132| [Permutations](https://leetcode.com/problems/permutations/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/Permutations.java) | LeetCode Online Judge |Backtracking | 146 | |133| [Maximum Distance in Arrays](https://leetcode.com/problems/maximum-distance-in-arrays/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MaximumDistanceinArrays.java) | LeetCode Online Judge | | 147 | |134| [Fizz Buzz](https://leetcode.com/problems/fizz-buzz/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/FizzBuzz.java) | LeetCode Online Judge | | 148 | |135| [Reverse String](https://leetcode.com/problems/reverse-string/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ReverseString.java) | LeetCode Online Judge | | 149 | |136| [Move Zeroes](https://leetcode.com/problems/move-zeroes/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MoveZeroes.java) | LeetCode Online Judge | | 150 | |137| [Missing Number](https://leetcode.com/problems/missing-number/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MissingNumber.java) | LeetCode Online Judge | | 151 | |138| [Repeated DNA Sequences](https://leetcode.com/problems/repeated-dna-sequences/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/RepeatedDNASequences.java) | LeetCode Online Judge | | 152 | |139| [Sum of Square Numbers](https://leetcode.com/problems/sum-of-square-numbers/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SumofSquareNumbers.java) | LeetCode Online Judge | | 153 | |140| [Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SumofTwoIntegers.java) | LeetCode Online Judge | Bit M. | 154 | |141| [Excel Sheet Column Number](https://leetcode.com/problems/excel-sheet-column-number/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ExcelSheetColumnNumber.java) | LeetCode Online Judge | | 155 | |142| [Array Partition I](https://leetcode.com/problems/array-partition-i/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ArrayPartitionI.java) | LeetCode Online Judge |MergeSort | 156 | |143| [Max Consecutive Ones](https://leetcode.com/problems/max-consecutive-ones/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MaxConsecutiveOnes.java) | LeetCode Online Judge | | 157 | |144| [Triangle](https://leetcode.com/problems/triangle/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/Triangle.java) | LeetCode Online Judge | | 158 | |145| [Minimum Path Sum](https://leetcode.com/problems/minimum-path-sum/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/MinimumPathSum.java) | LeetCode Online Judge | | 159 | |146| [ Summary Ranges](https://leetcode.com/problems/summary-ranges/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/SummaryRanges.java) | LeetCode Online Judge | | 160 | |147| [Partition List](https://leetcode.com/problems/partition-list/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/PartitionList.java) | LeetCode Online Judge | | 161 | |148| [Linked List Cycle](https://leetcode.com/problems/linked-list-cycle/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/LinkedListCycleHas.java) | LeetCode Online Judge |LinkedList | 162 | |149| [Reorder List](https://leetcode.com/problems/reorder-list/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ReorderList.java) | LeetCode Online Judge |LinkedList | 163 | |150| [Balanced Binary Tree](https://leetcode.com/problems/balanced-binary-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/BalancedBinaryTree.java) | LeetCode Online Judge |Tree | 164 | |151| [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/ValidateBinarySearchTree.java) | LeetCode Online Judge |Tree | 165 | |152| [Invert Binary Tree](https://leetcode.com/problems/invert-binary-tree/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/InvertBinaryTree.java) | LeetCode Online Judge | | 166 | |153| [Binary Tree Paths](https://leetcode.com/problems/binary-tree-paths/#/description) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode/BinaryTreePaths.java) | LeetCode Online Judge |DFS | 167 | |154| [Find Mode in Binary Search Tree](https://leetcode.com/problems/find-mode-in-binary-search-tree/#/description) | [Java]() | LeetCode Online Judge | | 168 | |155| [Path Sum III](https://leetcode.com/problems/path-sum-iii/#/description) | [Java]() | LeetCode Online Judge |Tree | 169 | |156| [Binary Tree Level Order Traversal](https://leetcode.com/problems/binary-tree-level-order-traversal/#/description) | [Java]() | LeetCode Online Judge | | 170 | |157| [ Binary Tree Level Order Traversal II](https://leetcode.com/problems/binary-tree-level-order-traversal-ii/#/description) | [Java]() | LeetCode Online Judge | | 171 | |158| [Average of Levels in Binary Tree](https://leetcode.com/problems/average-of-levels-in-binary-tree/#/description) | [Java]() | LeetCode Online Judge | | 172 | |159| [Reverse Nodes in k-Group](https://leetcode.com/problems/reverse-nodes-in-k-group/#/description) | [Java]() | LeetCode Online Judge |Tree | 173 | |160| [Maximum Product Subarray](https://leetcode.com/problems/maximum-product-subarray/#/description) | [Java]() | LeetCode Online Judge | | 174 | |161| [Kth Largest Element in an Array](https://leetcode.com/problems/kth-largest-element-in-an-array/#/description) | [Java]() | LeetCode Online Judge | | 175 | |162| [Kth Smallest Element in a BST](https://leetcode.com/problems/kth-smallest-element-in-a-bst/#/description) | [Java]() | LeetCode Online Judge | | 176 | |163| [Rotate List](https://leetcode.com/problems/rotate-list/#/description) | [Java]() | LeetCode Online Judge | | 177 | |164| [Combinations](https://leetcode.com/problems/combinations/#/description) | [Java]() | LeetCode Online Judge | | 178 | |165| [Path Sum II](https://leetcode.com/problems/path-sum-ii/#/description) | [Java]() | LeetCode Online Judge | | 179 | |166| [Sum Root to Leaf Numbers](https://leetcode.com/problems/sum-root-to-leaf-numbers/#/description) | [Java]() | LeetCode Online Judge | | 180 | |167| [Maximum Average Subarray I](https://leetcode.com/problems/maximum-average-subarray-i/#/description) | [Java]() | LeetCode Online Judge | | 181 | |168| [Combination Sum](https://leetcode.com/problems/combination-sum/#/description) | [Java]() | LeetCode Online Judge | | 182 | |169| [First Duplicate](https://codefights.com/interview-practice/task/pMvymcahZ8dY4g75q) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/arrays/FirstDuplicate.java) | Codefights | | 183 | |170| [First Not Repeating Character](https://codefights.com/interview-practice/task/uX5iLwhc6L5ckSyNC) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/arrays/FirstNotRepeatingCharacter.java) | Codefights | | 184 | |171| [Rotate Image](https://codefights.com/interview-practice/task/5A8jwLGcEpTPyyjTB) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/arrays/RotateImage.java) | Codefights | | 185 | |172| [Is CryptSolution](https://codefights.com/interview-practice/task/yM4uWYeQTHzYewW9H) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/arrays/IsCryptSolution.java) | Codefights | | 186 | |173| [Remove K From List](https://codefights.com/interview-practice/task/gX7NXPBrYThXZuanm) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/linkedlist/RemoveKFromList.java) | Codefights |Linkedlist | 187 | |174| [Is List Palindrome](https://codefights.com/interview-practice/task/HmNvEkfFShPhREMn4) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/linkedlist/IsListPalindrome.java) | Codefights |Linkedlist | 188 | |175| [Add Two Huge Numbers](https://codefights.com/interview-practice/task/RvDFbsNC3Xn7pnQfH) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/linkedlist/AddTwoHugeNumbers.java) | Codefights |Linkedlist | 189 | |176| [Merge Two LinkedLists](https://codefights.com/interview-practice/task/6rE3maCQwrZS3Mm2H) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/linkedlist/MergeTwoLinkedLists.java) | Codefights | | 190 | |177| [Reverse Nodes In K Groups](https://codefights.com/interview-practice/task/XP2Wn9pwZW6hvqH67) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/linkedlist/ReverseNodesInKGroups.java) | Codefights | | 191 | |178| [Rearrange Last N](https://codefights.com/interview-practice/task/5vcioHMkhGqkaQQYt) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/linkedlist/RearrangeLastN.java) | Codefights | | 192 | |179| [Grouping Dishes](https://codefights.com/interview-practice/task/xrFgR63cw7Nch4vXo) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/HashTables/GroupingDishes.java) | Codefights |HashTable | 193 | |180| [Are Following Patterns](https://codefights.com/interview-practice/task/3PcnSKuRkqzp8F6BN) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/tree/master/src/hashTables) | Codefights |HashTable | 194 | |181| [Contains Close Nums](https://codefights.com/interview-practice/task/njfXsvjRthFKmMwLC) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/hashTables/ContainsCloseNums.java) | Codefights |HashTable | 195 | |182| [Has Path With Given Sum](https://codefights.com/interview-practice/task/TG4tEMPnAc3PnzRCs) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/trees/HasPathWithGivenSum.java) | Codefights |Tree | 196 | |183| [Is Tree Symmetric](https://codefights.com/interview-practice/task/tXN6wQsTknDT6bNrf) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/trees/IsTreeSymmetric.java) | Codefights | | 197 | |184| [Find Profession](https://codefights.com/interview-practice/task/FwAR7koSB3uYYsqDp) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/trees/FindProfession.java) | Codefights | | 198 | |185| [Kth Largest In BST](https://codefights.com/interview-practice/task/jAKLMWLu8ynBhYsv6) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/trees/KthLargestInBST.java) | Codefights | | 199 | |186| [Is Subtree](https://codefights.com/interview-practice/task/mDpAJnDQkJqaYYsCg) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/trees/IsSubtree.java) | Codefights | | 200 | |187| [TraverseTree](https://codefights.com/interview-practice/task/PhNPP45hZGNwpPchi) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/dFSandBFS/TraverseTree.java) | Codefights |BFS | 201 | |188| [Largest Values In TreeRows](https://codefights.com/interview-practice/task/m9vC4ALaAeudkwRTF) | [Java]() | Codefights | | 202 | |189| [Digit Tree Sum](https://codefights.com/interview-practice/task/2oxNWXTS8eWBzvnRB) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/DFSandBFS/DigitTreeSum.java) | Codefights |DFS | 203 | |190| [Climbing Stairs](https://codefights.com/interview-practice/task/oJXTWuwEZiC6FTw3A) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/dynamicProgramming/ClimbingStairs.java) | Codefights |DP | 204 | |191| [House Robber](https://codefights.com/interview-practice/task/XBWN6DYRqPrKdMZs8) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/dynamicProgramming/HouseRobber.java) | Codefights |DP | 205 | |192| [Compose Ranges](https://codefights.com/interview-practice/task/cHYqbQ9DiWmejAdeG) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/dynamicProgramming/ComposeRanges.java) | Codefights |DP | 206 | |193| [Map Decoding](https://codefights.com/interview-practice/task/7o2Aba2Zep3MJPKQ3) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/dynamicProgramming/MapDecoding.java) | Codefights | | 207 | |194| [Climbing Stair case](https://codefights.com/interview-practice/task/cAXEnPyzknC5zgd7x) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/Backtracking/ClimbingStaircase.java) | Codefights | | 208 | |195| [Contains Duplicates](https://codefights.com/interview-practice/task/CfknJzPmdbstXhsoJ) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/CommonTechniques/ContainsDuplicates.java) | Codefights | | 209 | |196| [Sum Of Two](https://codefights.com/interview-practice/task/Hm98RnqK9Be575yoj) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/CommonTechniques/SumOfTwo.java) | Codefights | | 210 | |197| [Sum In Range](https://codefights.com/interview-practice/task/4MoqQLaw22nrzXbgs) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/CommonTechniques/SumInRange.java) | Codefights | | 211 | |198| [Array Max Consecutive Sum2](https://codefights.com/interview-practice/task/dQD4TCunke2JQ98rj) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/CommonTechniques/ArrayMaxConsecutiveSum2.java) | Codefights | | 212 | |199| [Find Longest Subarray By Sum](https://codefights.com/interview-practice/task/izLStwkDr5sMS9CEm) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/CommonTechniques/FindLongestSubarrayBySum.java) | Codefights | | 213 | |200| [Product Except Self](https://codefights.com/interview-practice/task/gxzW6jpXXkr3JNwXy) | [Java](https://github.com/edyluisrey/Codefights-Algorithms/blob/master/src/CommonTechniques/ProductExceptSelf.java) | Codefights | | 214 | |201| [Judge Route Circle](https://leetcode.com/problems/judge-route-circle/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/JudgeRouteCircle.java) | LeetCode Online Judge | | 215 | |202| [Find Anagram Mappings](https://leetcode.com/problems/find-anagram-mappings/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/AnagramMappings.java) | LeetCode Online Judge | | 216 | |203| [Jewels and Stones](https://leetcode.com/problems/jewels-and-stones/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/JewelsandStones.java) | LeetCode Online Judge | | 217 | |204| [Self Dividing Numbers](https://leetcode.com/problems/self-dividing-numbers/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/SelfDividingNumbers.java) | LeetCode Online Judge | | 218 | |205| [Baseball Game](https://leetcode.com/problems/baseball-game/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/BaseballGame.java) | LeetCode Online Judge | | 219 | |206| [Toeplitz Matrix](https://leetcode.com/problems/toeplitz-matrix/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/ToeplitzMatrix.java) | LeetCode Online Judge | | 220 | |207| [Distribute Candies](https://leetcode.com/problems/distribute-candies/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/DistributeCandies.java) | LeetCode Online Judge | | 221 | |208| [Add Strings](https://leetcode.com/problems/add-strings/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/AddStrings.java) | LeetCode Online Judge | | 222 | |209| [Relative Ranks](https://leetcode.com/problems/relative-ranks/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/RelativeRanks.java) | LeetCode Online Judge | | 223 | |210| [Assign Cookies](https://leetcode.com/problems/assign-cookies/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/AssignCookies.java) | LeetCode Online Judge | | 224 | |211| [Student Attendance Record I](https://leetcode.com/problems/student-attendance-record-i/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/StudentAttendanceRecordI.java) | LeetCode Online Judge | | 225 | |212| [Find the Difference](https://leetcode.com/problems/find-the-difference/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/FindtheDifference.java) | LeetCode Online Judge | | 226 | |213| [Longest Palindrome](https://leetcode.com/problems/longest-palindrome/discuss/89604/Simple-HashSet-solution-Java) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/LongestPalindrome.java) | LeetCode Online Judge | | 227 | |214| [Non-decreasing Array](https://leetcode.com/problems/non-decreasing-array/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/NondecreasingArray.java) | LeetCode Online Judge | | 228 | |215| [Count Binary Substrings](https://leetcode.com/problems/count-binary-substrings/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/CountBinarySubstrings.java) | LeetCode Online Judge | | 229 | |216| [Contains Duplicate II](https://leetcode.com/problems/contains-duplicate-ii/description/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/ContainsDuplicateII.java) | LeetCode Online Judge | | 230 | |217| [2D Array - DS](https://www.hackerrank.com/challenges/2d-array/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/TwoDArrayDS.java) | Hackerrank | | 231 | |218| [Arrays Left Rotation](https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/ArraysLeftRotation.java) | Hackerrank | | 232 | |219| [Hash Tables: Ransom Note](https://www.hackerrank.com/challenges/ctci-ransom-note/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/HashTablesRansomNote.java) | Hackerrank | | 233 | |220| [New Year Chaos](https://www.hackerrank.com/challenges/new-year-chaos/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/NewYearChaos.java) | Hackerrank | | 234 | |221| [Minimum Swaps 2](https://www.hackerrank.com/challenges/minimum-swaps-2/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/MinimumSwaps2.java) | Hackerrank | | 235 | |222| [Sherlock and Anagrams](https://www.hackerrank.com/challenges/sherlock-and-anagrams/problem) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/SherlockandAnagrams.java) | Hackerrank | | 236 | |223| [Count Triplets](https://www.hackerrank.com/challenges/count-triplets-1/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/CountTriplets.java) | Hackerrank | | 237 | |224| [Frequency Queries](https://www.hackerrank.com/challenges/frequency-queries/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=dictionaries-hashmaps) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/FrequencyQueries.java) | Hackerrank | | 238 | |225| [Array Manipulation](https://www.hackerrank.com/challenges/crush/problem?h_l=interview&playlist_slugs%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D=arrays) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/ArrayManipulation.java) | Hackerrank | | 239 | |226| [Making Anagrams](https://www.hackerrank.com/challenges/ctci-making-anagrams/problem?h_l=interview&playlist_slugs%5B%5D%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D%5B%5D=strings) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/MakingAnagrams.java) | Hackerrank | | 240 | |227| [Sherlock and the Valid String](https://www.hackerrank.com/challenges/sherlock-and-valid-string/problem?h_l=interview&playlist_slugs%5B%5D%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D%5B%5D=strings) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/SherlockValid.java) | Hackerrank | | 241 | |228| [Special Palindrome Again](https://www.hackerrank.com/challenges/special-palindrome-again/problem?h_l=interview&playlist_slugs%5B%5D%5B%5D=interview-preparation-kit&playlist_slugs%5B%5D%5B%5D=strings) | [Java](https://github.com/edyluisrey/Algorithms/blob/master/src/hackerrank/SpecialPalindromeAgain.java) | Hackerrank | | 242 | |229| [Longest Word in Dictionary](https://leetcode.com/problems/longest-word-in-dictionary/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/LongestWordDictionary.java) | Leetcode |Trie | 243 | |230| [ Implement Trie (Prefix Tree)](https://leetcode.com/problems/implement-trie-prefix-tree/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/ImplementPrefixTree.java) | Leetcode |Trie | 244 | |231| [Max Area of Island](https://leetcode.com/problems/max-area-of-island/) | [Java](https://github.com/edyluisrey/Leetcode-Algorithms/blob/master/src/leetcode2018/MaxAreaofIsland.java) | Leetcode | DFS| 245 | |232| []() | [Java]() | Leetcode | | 246 | |233| []() | [Java]() | Leetcode | | 247 | |234| []() | [Java]() | Leetcode | | 248 | |235| []() | [Java]() | Leetcode | | 249 | |236| []() | [Java]() | Leetcode | | 250 | |237| []() | [Java]() | Leetcode | | 251 | 252 | 253 | -------------------------------------------------------------------------------- /TEXQuotes.in: -------------------------------------------------------------------------------- 1 | "To be or not to be," quoth the Bard, "that 2 | is the question". 3 | The programming contestant replied: "I must disagree. 4 | To `C' or not to `C', that is The Question!" -------------------------------------------------------------------------------- /in.txt: -------------------------------------------------------------------------------- 1 | 0.0000001 2 | 0.0000002 3 | 0.0000003 -------------------------------------------------------------------------------- /src/general/Endofile.java: -------------------------------------------------------------------------------- 1 | package general; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Endofile { 6 | 7 | public static void main(String[] args) { 8 | Scanner sc= new Scanner(System.in); 9 | System.out.println("enter number:"); 10 | int num= sc.nextInt(); 11 | System.out.println(num); 12 | int line=0; 13 | System.out.println("Next:"+sc.hasNext()); 14 | while(sc.hasNext()){ 15 | line++; 16 | System.out.println(line+ " "+ sc.nextLine()); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/general/InputOutput.java: -------------------------------------------------------------------------------- 1 | package general; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.util.Scanner; 6 | 7 | public class InputOutput { 8 | 9 | public static void main(String[] args) { 10 | // TODO Auto-generated method stub 11 | Scanner in = new Scanner(System.in); 12 | int n= 0;//in.nextInt(); 13 | int a, b; 14 | while(n>0){ n--; 15 | a=in.nextInt(); 16 | b=in.nextInt(); 17 | System.out.printf("%d + %d =%d %n",a,b,a+b); 18 | } 19 | 20 | try { 21 | Scanner in2= new Scanner(new File("eof.in")); 22 | while(in2.hasNextLine()){ 23 | int num = in2.nextInt(); 24 | int sum=0; 25 | for(int i=0;i=0){ 14 | sum=0; 15 | for(int j=0; j< a.length;j++){ 16 | if(a[i]!=a[j]){ 17 | if(a[i]>a[j]) 18 | sum=sum+a[j]; 19 | } 20 | } 21 | if(a[i]>=sum) 22 | ind=true; 23 | else 24 | break; 25 | }else 26 | return 0; 27 | } 28 | if(ind) 29 | return 1; 30 | return 0; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/general/TestMUM.java: -------------------------------------------------------------------------------- 1 | package general; 2 | 3 | public class TestMUM { 4 | 5 | public static void main(String[] args) { 6 | System.out.println(isAsccending(123)); //1 7 | System.out.println(isAsccending(3124)); //0 8 | System.out.println(isAsccending(11)); //0 9 | System.out.println(isAsccending(3)); //1 10 | 11 | System.out.println("second "); 12 | System.out.println(isSarada(new int[]{1,5,13})); //1 13 | System.out.println(isSarada(new int[]{1,5})); //0 14 | System.out.println(isSarada(new int[]{1,5,13,7,8,5,13})); //1 15 | System.out.println(isSarada(new int[]{1,5,13,4,5})); //0 16 | System.out.println(isSarada(new int[]{1,3,13})); //1 17 | } 18 | 19 | static int isAsccending(int n){ 20 | int temp=0; 21 | int newNumber=n; 22 | if(n>=10) 23 | temp=newNumber%10+1; 24 | else 25 | return 1; 26 | int mod=0; 27 | 28 | while(newNumber>=10){ 29 | mod=newNumber%10; 30 | newNumber=newNumber/10; 31 | if(temp>mod){ 32 | temp=mod; 33 | }else 34 | return 0; 35 | } 36 | 37 | if(temp>newNumber) 38 | return 1; 39 | else 40 | return 0; 41 | } 42 | 43 | static int isSarada(int[] a){ 44 | 45 | for(int i=0;i arr, long r) { 10 | int re = 0; 11 | HashMap map1 = new HashMap<>(); 12 | HashMap map2 = new HashMap<>(); 13 | for(int i =0; i< arr.size(); i++) 14 | map1.put(arr.get(i), map1.getOrDefault(arr.get(i),0)+1); 15 | 16 | for(int i= 0; i < arr.size(); i++){ 17 | Long n= arr.get(i); 18 | if(n%r==0 && r!=1){ 19 | Integer left = map2.get(n/r); 20 | Integer rest = map2.get(n*r); 21 | Integer right= map1.get(n*r); 22 | if(rest!= null && right!=null) 23 | right= right - rest; 24 | if(left!=null && right!=null) 25 | re+= left* right; 26 | } 27 | map2.put(n, map2.getOrDefault(n,0)+1); 28 | } 29 | System.out.println(re); 30 | return re; 31 | } 32 | 33 | public static void main(String[] args){ 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/hackerrank/DesignerPDFViewer.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DesignerPDFViewer { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | int n = 26; 11 | int h[] = new int[n]; 12 | int max=0,pos; 13 | for(int h_i=0; h_i < n; h_i++){ 14 | h[h_i] = in.nextInt(); 15 | } 16 | String word = in.next(); 17 | for(int i=0;i freqQuery(List> queries) { 12 | Map map = new HashMap<>();; 13 | List list = new ArrayList<>(); 14 | for(int i = 0; i< queries.size(); i++){ 15 | int v = queries.get(i).get(1); 16 | if(queries.get(i).get(0)==1){ 17 | map.put(v, map.getOrDefault(v,0)+1); 18 | } 19 | if(queries.get(i).get(0)==2 && map.get(v)!=null){ 20 | if(map.get(v)<=1) 21 | map.remove(v); 22 | else 23 | map.put(v, map.get(v)-1); 24 | } 25 | if(queries.get(i).get(0)==3){ 26 | if(map.containsValue(v)) 27 | list.add(1); 28 | else 29 | list.add(0); 30 | } 31 | } 32 | return list; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/hackerrank/HashTablesRansomNote.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.HashMap; 4 | 5 | public class HashTablesRansomNote { 6 | 7 | // Complete the checkMagazine function below. 8 | static void checkMagazine(String[] magazine, String[] note) { 9 | HashMap map = new HashMap<>(); 10 | boolean re= true; 11 | for(String s: magazine){ 12 | if(map.containsKey(s)){ 13 | map.put(s,map.get(s)+1); 14 | }else{ 15 | map.put(s,1); 16 | } 17 | } 18 | for(String s: note){ 19 | if(map.containsKey(s) && map.get(s)>0){ 20 | map.put(s, map.get(s)-1); 21 | }else{ 22 | re= false; 23 | break; 24 | } 25 | } 26 | if(re) System.out.println("Yes"); 27 | else System.out.println("No"); 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/hackerrank/Hashset.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.HashSet; 4 | import java.util.Scanner; 5 | 6 | public class Hashset { 7 | 8 | public static void main(String[] args) { 9 | Scanner s = new Scanner(System.in); 10 | int t = s.nextInt(); 11 | String [] pair_left = new String[t]; 12 | String [] pair_right = new String[t]; 13 | 14 | for (int i = 0; i < t; i++) { 15 | pair_left[i] = s.next(); 16 | pair_right[i] = s.next(); 17 | } 18 | 19 | HashSet set= new HashSet(); 20 | int cont =0; 21 | for(int i=0;i map = new HashMap<>(); 18 | for(int i =0; i2){ 13 | failed = true; 14 | break; 15 | } 16 | for (int j = Math.max(0, q[i] - 2); j < i; j++) 17 | if (q[j] > q[i]) re++; 18 | } 19 | if(!failed) 20 | System.out.println(""+re); 21 | else 22 | System.out.println("Too chaotic"); 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/hackerrank/SherlockValid.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class SherlockValid { 7 | public static void main(String[] args){ 8 | System.out.println(isValid("abcdefghhgfedecba")); 9 | 10 | } 11 | 12 | // Complete the isValid function below. 13 | static String isValid(String s) { 14 | String r = "YES"; 15 | int max=0; 16 | int f=0; 17 | Map map1 = new HashMap<>(); 18 | Map map2 = new HashMap<>(); 19 | for(char c: s.toCharArray()){ 20 | map1.put(c, map1.getOrDefault(c,0)+1); 21 | } 22 | for(Character key : map1.keySet()){ 23 | map2.put(map1.get(key), map2.getOrDefault(map1.get(key),0)+1); 24 | } 25 | 26 | for(Integer key: map2.keySet()){ 27 | if(max1 && Math.abs(max-f)!=1) r="NO"; 39 | 40 | return r; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/hackerrank/SherlockandAnagrams.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.Arrays; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | public class SherlockandAnagrams { 8 | 9 | // Complete the sherlockAndAnagrams function below. 10 | static int sherlockAndAnagrams(String s) { 11 | Map map = new HashMap<>(); 12 | int n=0; 13 | for(int i=0; i< s.length(); i++){ 14 | for(int j = i+1; j<=s.length(); j++){ 15 | char[] c= s.substring(i,j).toCharArray(); 16 | Arrays.sort(c); 17 | String str = String.valueOf(c); 18 | if(map.containsKey(str)) 19 | map.put(str, map.get(str)+ 1); 20 | else 21 | map.put(str,1); 22 | } 23 | } 24 | for(String key: map.keySet()){ 25 | n += (map.get(key)*(map.get(key)-1))/2; 26 | } 27 | return n; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/hackerrank/SockMerchant.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SockMerchant { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | int s,t=0,n = in.nextInt(); 11 | int c[] = new int[n]; 12 | int temp[] = new int[n]; 13 | for(int c_i=0; c_i < n; c_i++){ 14 | c[c_i] = in.nextInt(); 15 | } 16 | for(int i=0;i=0 && s.charAt(l)==s.charAt(r) && s.charAt(i)!=s.charAt(r) && prev==s.charAt(r)){ 23 | l--; 24 | r++; 25 | sum=sum+1; 26 | } 27 | } 28 | return n+sum; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/hackerrank/Twin.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.Scanner; 4 | 5 | 6 | public class Twin { 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in= new Scanner(System.in); 10 | int n= in.nextInt(); 11 | int m= in.nextInt(); 12 | int count=0; 13 | for(int i=n; i<=m;i++){ 14 | for(int j=i+1;j<=i+2;j++){ 15 | if(!(j<=m)) break; 16 | int ci=0; 17 | for(int p=1;p<=i;p++){ 18 | if(i%p==0) ci++; 19 | } 20 | if(ci==2){ 21 | if(Math.abs(j-i)==2 || i!=1){ 22 | int cj=0; 23 | for(int jp=1;jp*jp<=j;jp++){ 24 | if(j%jp==0) cj++; 25 | } 26 | if(cj==2) 27 | count++; 28 | } 29 | } 30 | } 31 | } 32 | System.out.println(count); 33 | } 34 | 35 | } 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /src/hackerrank/TwoDArrayDS.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | public class TwoDArrayDS { 4 | 5 | // Complete the hourglassSum function below. 6 | static int hourglassSum(int[][] arr) { 7 | int sum = -100; 8 | for(int i = 0; i<= 3; i++){ 9 | for(int j = 0; j <=3 ; j++){ 10 | int subSum = 0; 11 | int k =0; 12 | for(int m = i; m< i+3; m++){ 13 | for(int n= j ; n < j+3; n++){ 14 | if(k==1){ 15 | if(n==j+1){ 16 | subSum = subSum + arr[m][n]; 17 | } 18 | }else{ 19 | subSum = subSum+ arr[m][n]; 20 | } 21 | } 22 | k++; 23 | } 24 | if(sum< subSum) 25 | sum = subSum; 26 | System.out.println("i:"+i + " j:"+j + " sum:"+ sum); 27 | } 28 | } 29 | return sum; 30 | 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/hackerrank/UtopianTree.java: -------------------------------------------------------------------------------- 1 | package hackerrank; 2 | 3 | import java.util.Scanner; 4 | 5 | public class UtopianTree { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | int t = in.nextInt(); 11 | for(int a0 = 0; a0 < t; a0++){ 12 | int n = in.nextInt(); 13 | int h=1; 14 | for(int j=1;j<=n;j++){ 15 | if(j%2==0) 16 | h=h+1; 17 | else 18 | h=h*2; 19 | } 20 | System.out.println(h); 21 | } 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/queue/PriorityCustomer.java: -------------------------------------------------------------------------------- 1 | package queue; 2 | 3 | import java.util.Comparator; 4 | import java.util.PriorityQueue; 5 | import java.util.Queue; 6 | 7 | class Customer { 8 | private int id; 9 | private String name; 10 | 11 | public Customer(int i, String n){ 12 | this.id=i; 13 | this.name=n; 14 | } 15 | 16 | public int getId() { 17 | return id; 18 | } 19 | 20 | public void setId(int id) { 21 | this.id = id; 22 | } 23 | 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | } 33 | 34 | public class PriorityCustomer{ 35 | 36 | static class PQsort implements Comparator { 37 | @Override 38 | public int compare(Customer one, Customer two) { 39 | return two.getId() - one.getId(); 40 | } 41 | } 42 | 43 | public static void main(String[] args) { 44 | PQsort pqs = new PQsort(); 45 | Queue PriorityCustomer = new PriorityQueue<>(2,pqs); 46 | Customer c1= new Customer(4,"Juan"); 47 | Customer c2= new Customer(1,"Manuel"); 48 | Customer c3= new Customer(2,"Edy"); 49 | 50 | PriorityCustomer.add(c1); 51 | PriorityCustomer.add(c2); 52 | PriorityCustomer.add(c3); 53 | 54 | Customer ctm1 = PriorityCustomer.poll(); 55 | Customer ctm2 = PriorityCustomer.poll(); 56 | Customer ctm3 = PriorityCustomer.poll(); 57 | System.out.println(ctm1.getId()+ " : "+ ctm1.getName()); 58 | System.out.println(ctm2.getId()+ " : "+ ctm2.getName()); 59 | System.out.println(ctm3.getId()+ " : "+ ctm3.getName()); 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/sortSearch/BubbleSort.java: -------------------------------------------------------------------------------- 1 | package sortSearch; 2 | 3 | import java.util.Vector; 4 | 5 | interface ComparePrices{ 6 | boolean lessThan(Object o); 7 | boolean greaterThan(Object o); 8 | } 9 | 10 | class VegetarianDish implements ComparePrices{ 11 | private int price; 12 | private String name; 13 | 14 | VegetarianDish(int price,String name){ 15 | this.price=price; 16 | this.name=name; 17 | } 18 | 19 | @Override 20 | public boolean lessThan(Object o) { 21 | // TODO Auto-generated method stub 22 | return false; 23 | } 24 | 25 | @Override 26 | public boolean greaterThan(Object o) { 27 | // TODO Auto-generated method stub 28 | VegetarianDish vd2= (VegetarianDish) o; 29 | return price > vd2.price; 30 | } 31 | 32 | @Override 33 | public String toString(){ 34 | return "price:"+price+ " name:"+name; 35 | } 36 | 37 | } 38 | 39 | public class BubbleSort { 40 | 41 | public static void sort(Vector v){ 42 | int j; 43 | boolean flag=true; 44 | Object temp; 45 | while ( flag ) 46 | { 47 | flag= false; 48 | for( j=0; j < v.size() -1; j++ ) 49 | { 50 | VegetarianDish vd= (VegetarianDish)v.elementAt(j); 51 | if(vd.greaterThan(v.elementAt(j+1))){ 52 | flag=true; 53 | temp= v.elementAt(j); 54 | v.setElementAt(v.elementAt(j+1), j); 55 | v.setElementAt(temp, j+1); 56 | } 57 | } 58 | } 59 | } 60 | 61 | public static void main(String[] args) { 62 | VegetarianDish vd1= new VegetarianDish(3,"Lettuce sandwich"); 63 | VegetarianDish vd2= new VegetarianDish(1,"Broccoli slaw"); 64 | VegetarianDish vd3= new VegetarianDish(2,"Green papaya salad"); 65 | Vector v = new Vector(); 66 | v.add(vd1); 67 | v.add(vd2); 68 | v.add(vd3); 69 | sort(v); 70 | for (Object o : v) { 71 | System.out.print(o + " "); 72 | } 73 | 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/sortSearch/ExchangeSort.java: -------------------------------------------------------------------------------- 1 | package sortSearch; 2 | 3 | import java.util.Arrays; 4 | 5 | public class ExchangeSort { 6 | 7 | public static void swap(int a[],int i, int j){ 8 | int temp=a[i]; 9 | a[i]=a[j]; 10 | a[j]=temp; 11 | } 12 | 13 | public static void sort(int a[]){ 14 | for(int i=0;ia[j]){ 17 | swap(a,i,j); 18 | } 19 | } 20 | } 21 | } 22 | 23 | public static void main(String[] args) { 24 | int a[]= {5,1,9,2,4,3}; 25 | sort(a); 26 | System.out.println(Arrays.toString(a)); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/sortSearch/InsertionSort.java: -------------------------------------------------------------------------------- 1 | package sortSearch; 2 | 3 | import java.util.Arrays; 4 | 5 | public class InsertionSort { 6 | 7 | public static void sort(int a[]){ 8 | int aux,elem; 9 | for(int i=1;i0 && auxpivot) 16 | j--; 17 | if(i<=j){ 18 | swap(arr,i,j); 19 | i++; 20 | j--; 21 | } 22 | }while(i<=j); 23 | if(left0;gap=gap/2){ 9 | for( int i = gap; i < a.length; i++ ) 10 | { 11 | int j=i-gap; 12 | while(j>=0){ 13 | int tem=j+gap; 14 | if(a[j]>a[tem]){ 15 | j=-1; 16 | }else{ 17 | swap(a,j,tem); 18 | j-=gap; 19 | } 20 | } 21 | } 22 | } 23 | } 24 | 25 | public static void swap(int a[],int i, int j){ 26 | int temp=a[i]; 27 | a[i]=a[j]; 28 | a[j]=temp; 29 | } 30 | 31 | public static void main(String[] args) { 32 | // TODO Auto-generated method stub 33 | int a[]= {6,0,3,7,1,5,9}; 34 | sort(a); 35 | System.out.println(Arrays.toString(a)); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/uva/AutomaticAnswer.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | /*Automatic Answer*/ 5 | public class AutomaticAnswer { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | int t, total,n,d; 9 | t=in.nextInt(); 10 | while((t--)!=0){ 11 | n= in.nextInt(); 12 | total=(((((n*567)/9)+7492)*235)/47)-498; 13 | d= total/10; 14 | System.out.println(Math.abs(d%10)); 15 | } 16 | 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/uva/Bafana.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Bafana { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int n,k,p,position,cas=1; 10 | int t= in.nextInt(); 11 | while((t--)!=0){ 12 | n=in.nextInt(); 13 | k=in.nextInt(); 14 | p=in.nextInt(); 15 | position= (((k-1)+p)%n)+1; 16 | System.out.printf("Case %d: %d%n",cas++,position); 17 | } 18 | 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/uva/BeatSpread.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BeatSpread { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int n,s,d,x,y; 10 | n=in.nextInt(); 11 | while((n--)!=0){ 12 | s=in.nextInt(); 13 | d=in.nextInt(); 14 | if(d>s || (s-d)%2!=0) 15 | System.out.println("impossible"); 16 | else{ 17 | y=(s-d)/2; 18 | x=y+d; 19 | System.out.printf("%d %d%n",x,y); 20 | } 21 | } 22 | 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /src/uva/BigChocolate.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BigChocolate { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int m,n; 10 | while(in.hasNext()){ 11 | m= in.nextInt(); 12 | n=in.nextInt(); 13 | System.out.println(m*n-1); 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/uva/BlowingFuses.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BlowingFuses { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | int nd,no,c,currentCons,max,temp,ccase = 1; 11 | boolean blown; 12 | nd=in.nextInt(); 13 | while (nd != 0) { 14 | currentCons = 0;max=0; 15 | no = in.nextInt(); 16 | c = in.nextInt(); 17 | blown = false; 18 | boolean[] states=new boolean[nd]; 19 | int[] devConsump= new int[nd]; 20 | for(int i = 0; i < nd; i++) { 21 | devConsump[i] = in.nextInt(); 22 | states[i] = false; 23 | } 24 | 25 | for(int i = 0; i < no; i++) { 26 | temp = in.nextInt(); 27 | if(!states[temp-1]) { 28 | states[temp-1] = true; 29 | currentCons += devConsump[temp-1]; 30 | if(currentCons > c) 31 | blown = true; 32 | if(currentCons > max) 33 | max = currentCons; 34 | } else { 35 | currentCons -= devConsump[temp-1]; 36 | states[temp-1] = false; 37 | } 38 | } 39 | System.out.println("Sequence " + ccase); 40 | if(blown) 41 | System.out.println("Fuse was blown.\n"); 42 | else{ 43 | System.out.println("Fuse was not blown."); 44 | System.out.println("Maximal power consumption was " + max + " amperes.\n"); 45 | } 46 | 47 | nd = in.nextInt(); 48 | ccase++; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/uva/BoxBricks.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class BoxBricks { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int avr,moves,n,totalBricks,count=1; 10 | int[] a; 11 | while(true){ 12 | n=in.nextInt(); 13 | if(n<=0) break; 14 | a=new int[n]; 15 | moves=0; 16 | totalBricks=0; 17 | for(int i=0;iavr) 24 | moves=moves+(a[i]-avr); 25 | } 26 | System.out.println("Set #"+count); 27 | System.out.printf("The minimum number of moves is %d.%n%n",moves); 28 | count++; 29 | } 30 | 31 | } 32 | 33 | } -------------------------------------------------------------------------------- /src/uva/Brainfuck.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class Brainfuck { 8 | 9 | public static void main(String[] args) throws IOException { 10 | // TODO Auto-generated method stub 11 | BufferedReader in= new BufferedReader(new InputStreamReader(System.in)); 12 | int t,count=1; 13 | String line; 14 | t= Integer.parseInt(in.readLine()); 15 | while((t--)!=0) 16 | { 17 | line = in.readLine(); 18 | int pointer=0; 19 | int[] mem= new int[100]; 20 | for(int i=0;i'){ 23 | pointer=(pointer+1)%100; 24 | continue; 25 | } 26 | else if(line.charAt(i)=='<') { 27 | pointer=(pointer-1+100)%100; 28 | continue; 29 | } 30 | else if(line.charAt(i)=='+'){ 31 | mem[pointer]=(mem[pointer]+1)%256; 32 | continue; 33 | } 34 | else if(line.charAt(i)=='-') 35 | mem[pointer]=(mem[pointer]-1+256)%256; 36 | } 37 | System.out.printf("Case %d:",count); 38 | for(int i=0;i<100;i++) 39 | System.out.printf(" %02X", mem[i]); 40 | System.out.println(); 41 | count++; 42 | } 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/uva/BurgerTime.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class BurgerTime { 8 | 9 | public static void main(String[] args) throws NumberFormatException, IOException { 10 | // TODO Auto-generated method stub 11 | BufferedReader in = new BufferedReader (new InputStreamReader(System.in)); 12 | int s; 13 | String temp,line; 14 | while((temp=in.readLine())!=null){ 15 | s = Integer.parseInt(temp); 16 | if(s == 0) 17 | break; 18 | line = in.readLine(); 19 | int D = -1; 20 | int R = -1; 21 | int min = Integer.MAX_VALUE; 22 | for (int i = 0; i < line.length(); i++) { 23 | if (line.charAt(i)== 'Z') { 24 | min = 0; 25 | break; 26 | } else if (line.charAt(i) == 'R') { 27 | R = i; 28 | } else if (line.charAt(i) == 'D') { 29 | D=i; 30 | } 31 | if (D != -1 && R != -1) { 32 | min = Math.min(Math.abs(D - R), min); 33 | } 34 | } 35 | System.out.println(min); 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/uva/ClockHands.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ClockHands { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | String s; 10 | double h,m,hAngle,mAngle,diff; 11 | while(true){ 12 | s=in.next(); 13 | String[] a=s.split(":"); 14 | h=Double.parseDouble(a[0]); 15 | m=Double.parseDouble(a[1]); 16 | if(h==0 && m==0) break; 17 | h=h+m/60; 18 | hAngle= h*30; 19 | mAngle= m*6; 20 | diff=Math.abs(hAngle-mAngle); 21 | if(diff>180) 22 | diff=360-diff; 23 | System.out.printf("%.3f%n",diff); 24 | } 25 | 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/uva/CombinationLock.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class CombinationLock { 6 | 7 | public static void main(String[] args) { 8 | Scanner scanner = new Scanner(System.in); 9 | while(true) { 10 | int n1,n2,n3,n4,total,degrees=360/40; 11 | n1 = scanner.nextInt(); 12 | n2 = scanner.nextInt(); 13 | n3 = scanner.nextInt(); 14 | n4 = scanner.nextInt(); 15 | if((n1 == 0) && (n2 == 0) && (n3 == 0) && (n4 == 0)) 16 | break; 17 | total=120; //40x3 18 | if (n2>n1) { 19 | total+=40-n2+n1; 20 | } else { 21 | total+=n1-n2; 22 | } 23 | 24 | if (n3>n2) { 25 | total+=(n3-n2); 26 | } else { 27 | total+=40-n2+n3; 28 | } 29 | 30 | if (n4>n3) { 31 | total+=40-n4+n3; 32 | } else { 33 | total+=n3-n4; 34 | } 35 | 36 | System.out.println(total*degrees); 37 | } 38 | scanner.close(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/uva/CostCutting.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Arrays; 4 | import java.util.Scanner; 5 | 6 | public class CostCutting { 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int t,i=0; 10 | t=in.nextInt(); 11 | while((t--)!=0){ i++; 12 | int[] a= new int[3]; 13 | a[0]= in.nextInt(); 14 | a[1]= in.nextInt(); 15 | a[2]= in.nextInt(); 16 | Arrays.sort(a); 17 | System.out.printf("Case %d: %d%n",i,a[1]); 18 | } 19 | in.close(); 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/uva/DigitCounting.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class DigitCounting { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int t,n; 10 | t= in.nextInt(); 11 | while((t--)!=0){ 12 | n=in.nextInt(); 13 | StringBuilder str = new StringBuilder(""); 14 | for(int i=0;i0) 23 | System.out.printf(" "); 24 | System.out.printf("%d",result[k]); 25 | } 26 | System.out.println(); 27 | } 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/uva/DivisionNlogonia.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | /*Division of Nlogonia*/ 6 | public class DivisionNlogonia { 7 | 8 | public static void main(String[] args) { 9 | int t, mx,ny,px,py; 10 | Scanner in = new Scanner(System.in); 11 | t=in.nextInt(); 12 | while(t!=0){ 13 | mx= in.nextInt(); 14 | ny=in.nextInt(); 15 | while(t>0){ 16 | t--; 17 | px= in.nextInt(); 18 | py=in.nextInt(); 19 | if(px==mx){ 20 | System.out.println("divisa"); 21 | continue;} 22 | if(py==ny){ 23 | System.out.println("divisa"); 24 | continue;} 25 | if(px>mx){ 26 | if(py>ny) 27 | System.out.println("NE"); 28 | else 29 | System.out.println("SE"); 30 | continue; 31 | 32 | } 33 | if(py>ny) 34 | System.out.println("NO"); 35 | else 36 | System.out.println("SO"); 37 | 38 | } 39 | } 40 | in.close(); 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/uva/Egypt.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Egypt { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int a,b,c; 10 | while(true){ 11 | a=in.nextInt(); 12 | b=in.nextInt(); 13 | c=in.nextInt(); 14 | if(a==0 && b==0 && c==0) break; 15 | if(a*a==b*b+c*c) 16 | System.out.println("right"); 17 | else if(b*b==a*a+c*c) 18 | System.out.println("right"); 19 | else if(c*c==b*b+a*a) 20 | System.out.println("right"); 21 | else 22 | System.out.println("wrong"); 23 | } 24 | 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /src/uva/EmoogleBalance.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | /*import java.util.Scanner; 4 | 5 | public class EmoogleBalance { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int value, balan, t,i=0; 10 | t= in.nextInt(); 11 | while(t!=0){ 12 | balan=0; 13 | i++; 14 | while((t--)!=0){ 15 | value=in.nextInt(); 16 | if(value==0) 17 | balan--; 18 | else 19 | balan++; 20 | } 21 | System.out.printf("Case %d: %d%n",i,balan); 22 | t= in.nextInt(); 23 | } 24 | 25 | } 26 | 27 | } */ 28 | 29 | 30 | import java.util.Scanner; 31 | 32 | public class EmoogleBalance { 33 | public static void main(String[] args) { 34 | Scanner in = new Scanner(System.in); 35 | int t, nf,s,d,a,sum; 36 | t=in.nextInt(); 37 | while((t--)!=0) { 38 | sum=0; 39 | nf=in.nextInt(); 40 | while((nf--)!=0){ 41 | s=in.nextInt(); 42 | a=in.nextInt(); 43 | d=in.nextInt(); 44 | sum= sum+s*d; 45 | } 46 | System.out.println(sum); 47 | 48 | } 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/uva/F91.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class F91 { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int n; 10 | while((n = in.nextInt())!=0){ 11 | if(n<=100) 12 | System.out.printf("f91(%d) = 91\n",n); 13 | else 14 | System.out.printf("f91(%d) = %d\n",n,n-10); 15 | } 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/uva/FlipSort.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class FlipSort { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | while(in.hasNext()){ 11 | int n=in.nextInt(); 12 | int a[] = new int[n]; 13 | for(int i=0;ia[j]) 20 | total++; 21 | } 22 | System.out.println("Minimum exchange operations : "+total); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/uva/FormingQuizTeams.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.io.InputStreamReader; 4 | import java.util.Scanner; 5 | 6 | /*10911 - Forming Quiz Teams*/ 7 | 8 | public class FormingQuizTeams { // Main 9 | 10 | public static void main(String[] args) { 11 | Scanner in= new Scanner(new InputStreamReader(System.in)); 12 | while(true){ 13 | int n = in.nextInt(); 14 | if(n==0) 15 | break; 16 | String[] names= new String[16]; 17 | int[] x= new int[16]; 18 | int[] y= new int[16]; 19 | if(n<=8){ 20 | for(int i=0;i= np) 23 | all = true; 24 | i++; 25 | } 26 | 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/uva/HelloWorld.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class HelloWorld { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int cont=1,n,copy,numcopys; 10 | while(true){ 11 | n=in.nextInt(); 12 | if(n<=0) break; 13 | copy=1; 14 | numcopys=0; 15 | while(copynewWall) 22 | lj++; 23 | current= newWall; 24 | } 25 | System.out.println("Case " + i +": " + hj + " " + lj); 26 | i++; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/uva/LaserSculpture.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class LaserSculpture { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | int a, c, count; 11 | while(true) 12 | { a=in.nextInt(); 13 | if(a==0) 14 | break; 15 | c=in.nextInt(); 16 | int[] v =new int[c]; 17 | count = 0; 18 | for(int i=0; i=sum2) 37 | System.out.printf("%.2f %c%n",sum2*100.0/sum1,'%'); 38 | else 39 | System.out.printf("%.2f %c%n",sum1*100.0/sum2,'%'); 40 | 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/uva/P12578.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class P12578 { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int t= in.nextInt(); 10 | double l,area,green; 11 | while((t--)!=0){ 12 | l= in.nextDouble(); 13 | area= Math.PI*(l/5)*(l/5); 14 | green=l*l*0.6-area; 15 | System.out.printf("%.2f %.2f%n",area,green); 16 | } 17 | 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/uva/Parking.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class Parking { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | int n, s, pos,min,max; 9 | n= in.nextInt(); 10 | while((n--)!=0){ 11 | s=in.nextInt(); 12 | min=100;max=0; 13 | while((s--)!=0){ 14 | pos= in.nextInt(); 15 | if(pos>max) 16 | max =pos; 17 | if(pos=k){ 15 | total+=n/k; 16 | n=(n/k)+(n%k); 17 | } 18 | System.out.println(total); 19 | } 20 | 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /src/uva/PowerCryptography.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PowerCryptography { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | while(in.hasNextDouble()){ 10 | double n=in.nextDouble(); 11 | double p=in.nextDouble(); 12 | double result=Math.round(Math.pow(p,1/n )); 13 | System.out.printf("%d%n",(int)result ); 14 | } 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/uva/Prerequisites.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Scanner; 6 | 7 | public class Prerequisites { 8 | 9 | public static void main(String[] args) { 10 | // TODO Auto-generated method stub 11 | Scanner in = new Scanner(System.in); 12 | int k,category,c,r; 13 | String temp,cCourse; 14 | boolean getDegree; 15 | while ((k=in.nextInt())!=0) { 16 | category = in.nextInt(); 17 | Map fCourses= new HashMap(); 18 | getDegree=true; 19 | for ( int i = 0; i < k; i++) { 20 | temp=in.next(); 21 | fCourses.put(temp, 1); 22 | } 23 | 24 | for ( int i = 0; i < category; i++ ) { 25 | c= in.nextInt(); 26 | r= in.nextInt(); 27 | for ( int j = 0; j < c; j++ ) { 28 | cCourse = in.next(); 29 | if(fCourses.get(cCourse)!=null) 30 | r--; 31 | } 32 | if ( r > 0 ) 33 | getDegree = false; 34 | } 35 | 36 | if ( getDegree ) 37 | System.out.println("yes"); 38 | else 39 | System.out.println("no"); 40 | } 41 | 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/uva/PrimaryArithmetic.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class PrimaryArithmetic { 6 | 7 | public static void main(String[] args) { 8 | Scanner in =new Scanner(System.in); 9 | int a,b,carry,times,sum; 10 | while(true){ 11 | a=in.nextInt(); 12 | b=in.nextInt(); 13 | if(a==0 && b==0) break; 14 | carry=0; 15 | times=0; 16 | while(a>0 || b>0){ 17 | sum= a%10+b%10+carry; 18 | if(sum>=10) 19 | times++; 20 | a=a/10; 21 | b=b/10; 22 | carry=sum/10; 23 | } 24 | 25 | if(times==0) 26 | System.out.println("No carry operation."); 27 | else if(times==1) 28 | System.out.printf("%d carry operation.%n",times); 29 | else 30 | System.out.printf("%d carry operations.%n",times); 31 | 32 | } 33 | 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/uva/RequestProposal.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.StringTokenizer; 7 | 8 | public class RequestProposal { 9 | 10 | public static void main(String[] args) throws NumberFormatException, IOException { 11 | // TODO Auto-generated method stub 12 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 13 | int n, p, r,cont=1; 14 | String namepr, bname="",line; 15 | double d, bestCompliance, price; 16 | StringTokenizer st = null; 17 | 18 | while((line = in.readLine()) != null) { 19 | st = new StringTokenizer(line); 20 | n=Integer.parseInt(st.nextToken()); 21 | p=Integer.parseInt(st.nextToken()); 22 | if(n == 0 && p == 0) 23 | break; 24 | for(int i = 0; i < n; i++) 25 | in.readLine(); 26 | 27 | bestCompliance = 0.0; 28 | price = 2000000000; 29 | for(int i = 0; i < p; i++) { 30 | namepr=in.readLine(); 31 | st = new StringTokenizer(in.readLine()); 32 | d= Double.parseDouble(st.nextToken()); 33 | r=Integer.parseInt(st.nextToken()); 34 | for(int j = 0; j < r; j++) 35 | in.readLine(); 36 | if((float) r / p >bestCompliance || (float) r / p == bestCompliance && d < price) { 37 | bestCompliance = (float) r / p; 38 | price = d; 39 | bname = namepr; 40 | } 41 | } 42 | if(cont > 1) 43 | System.out.println(); 44 | System.out.println("RFP #"+cont); 45 | System.out.println(bname); 46 | cont++; 47 | } 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/uva/ReverseAdd.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class ReverseAdd { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int t,it; 10 | long n,rev; 11 | t= in.nextInt(); 12 | while((t--)!=0){ 13 | n=in.nextInt(); 14 | it=0; 15 | rev=reverse(n); 16 | while(n!=rev){ 17 | n=n+rev; 18 | rev=reverse(n); 19 | it++; 20 | 21 | } 22 | System.out.printf("%d %d%n",it,n); 23 | } 24 | 25 | } 26 | 27 | static long reverse(long n){ 28 | long d, reverse=0; 29 | while(n>0){ 30 | d=n%10; 31 | reverse=reverse*10+d; 32 | n=n/10; 33 | } 34 | return reverse; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/uva/RobotInstructions.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class RobotInstructions { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int n,cont; 10 | String cp; 11 | int t = in.nextInt(); 12 | while((t--)!= 0) { 13 | cont = 0; 14 | n = in.nextInt(); 15 | int[] instructions = new int[n]; 16 | for(int i = 0; i < n; i++) { 17 | cp = in.next(); 18 | if(cp.startsWith("L")) { 19 | instructions[i] = -1; 20 | cont--; 21 | } else if(cp.startsWith("R")) { 22 | instructions[i] = 1; 23 | cont++; 24 | } else { 25 | in.next(); 26 | int tmp = in.nextInt(); 27 | instructions[i] = instructions[tmp-1]; 28 | if(instructions[i] == -1) 29 | cont--; 30 | else 31 | cont++; 32 | } 33 | } 34 | System.out.println(cont); 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/uva/SMSTyping.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Scanner; 6 | 7 | public class SMSTyping { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | int t, to,cont=1; 12 | t= Integer.parseInt(in.nextLine()); 13 | Map map= new HashMap<>(); 14 | map.put("a", 1); map.put("b", 2); map.put("c", 3); 15 | map.put("d", 1); map.put("e", 2); map.put("f", 3); 16 | map.put("g", 1); map.put("h", 2); map.put("i", 3); 17 | map.put("j", 1); map.put("k", 2); map.put("l", 3); 18 | map.put("m", 1); map.put("n", 2); map.put("o", 3); 19 | map.put("p", 1); map.put("q", 2); map.put("r", 3); map.put("s", 4); 20 | map.put("t", 1); map.put("u", 2); map.put("v", 3); 21 | map.put("w", 1); map.put("x", 2); map.put("y", 3); map.put("z", 4); 22 | 23 | while(cont<=t){ 24 | String s= in.nextLine(); 25 | to=0; 26 | for(int i=0;id || c>b) 32 | System.out.printf("Case %d: Hits Meeting\n",i); 33 | else 34 | System.out.printf("Case %d: Mrs Meeting\n",i); 35 | i++; 36 | 37 | } 38 | 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/uva/SearchingNessy.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | /*Searching for Nessy*/ 5 | public class SearchingNessy { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int n,a,b; 10 | n= in.nextInt(); 11 | while(n>0){ 12 | n--; 13 | a= in.nextInt(); 14 | b= in.nextInt(); 15 | System.out.println((int)(Math.floor((a)/3)*Math.floor((b)/3))); 16 | } 17 | in.close(); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/uva/SecretResearch.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SecretResearch { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int n= Integer.parseInt(in.next()); 10 | String s; 11 | while((n--)!=0){ 12 | s=in.next(); 13 | if(s.equals("1") || s.equals("4") || s.equals("78")) System.out.println("+"); 14 | else if(s.endsWith("35")) System.out.println("-"); 15 | else if(s.startsWith("9") && s.endsWith("4")) System.out.println("*"); 16 | else if(s.startsWith("190")) System.out.println("?"); 17 | } 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /src/uva/SquareNumbers.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SquareNumbers { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int a,b,total,root; 10 | while(true){ 11 | a= in.nextInt(); 12 | b=in.nextInt(); 13 | if(a==0 && b==0) break; 14 | total=0; 15 | for(int i =a;i<=b;i++){ 16 | root = (int)Math.sqrt(i); 17 | if(root*root==i) 18 | total++; 19 | } 20 | System.out.println(total); 21 | } 22 | 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/uva/SubPrime.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SubPrime { 6 | public static void main(String[] args) { 7 | Scanner in = new Scanner(System.in); 8 | int Banks,Debetures,db,cb,v; 9 | boolean flag; 10 | while(true) { 11 | Banks = in.nextInt(); 12 | Debetures = in.nextInt(); 13 | if(Banks==0 && Debetures==0) 14 | break; 15 | int[] b = new int[Banks]; 16 | for(int i = 0; i < Banks; i++) { 17 | b[i] = in.nextInt(); 18 | } 19 | for(int i = 0; i < Debetures; i++) { 20 | db = in.nextInt(); 21 | cb = in.nextInt(); 22 | v = in.nextInt(); 23 | b[db - 1] -= v; 24 | b[cb - 1] += v; 25 | } 26 | flag=true; 27 | for(int i = 0; i < Banks; i++) { 28 | if(b[i] < 0) { 29 | flag=false; 30 | break; 31 | } 32 | } 33 | if(flag) 34 | System.out.println("S"); 35 | else 36 | System.out.println("N"); 37 | } 38 | } 39 | } 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /src/uva/SummingDigits.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SummingDigits { 6 | 7 | public static void main(String[] args) { 8 | Scanner in= new Scanner(System.in); 9 | int n, s; 10 | while((n=in.nextInt())!=0){ 11 | s= sum(n); 12 | System.out.println(s); 13 | } 14 | } 15 | static int sum(int n){ 16 | int sum = 0; 17 | for(int i=n;i!=0;i=i/10){ 18 | sum = sum +i%10; 19 | } 20 | if(sum<10) 21 | return sum; 22 | else 23 | return sum(sum); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/uva/SwallowingGround.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class SwallowingGround { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in= new Scanner(System.in); 10 | int t,nc,x,y,gap; 11 | boolean temp; 12 | t = in.nextInt(); 13 | while((t--) > 0) { 14 | nc= in.nextInt(); 15 | x = in.nextInt(); 16 | y = in.nextInt(); 17 | gap = Math.abs(x - y); 18 | temp = true; 19 | while((nc--) > 1) { 20 | x = in.nextInt(); 21 | y = in.nextInt(); 22 | if(Math.abs(x - y) != gap) 23 | temp = false; 24 | } 25 | if(temp) 26 | System.out.println("yes"); 27 | else 28 | System.out.println("no"); 29 | if(t != 0) 30 | System.out.println(""); 31 | } 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/uva/TEXQuotes.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.util.Scanner; 6 | 7 | /*272 - TEX Quotes*/ 8 | public class TEXQuotes { 9 | 10 | public static void main(String[] args) { 11 | try { 12 | Scanner in= new Scanner(new File("TEXQuotes.in")); 13 | boolean start= true; 14 | while(in.hasNextLine()){ 15 | String line = in.nextLine(); 16 | for(int i=0;i jCost) { 25 | System.out.println("Case " + i + ": Juice " + jCost); 26 | } else { 27 | System.out.println("Case " + i + ": Mile Juice "+ mCost); 28 | } 29 | i++; 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/uva/Ternary.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | import java.util.Stack; 5 | 6 | public class Ternary { 7 | 8 | public static void main(String[] args) { 9 | // TODO Auto-generated method stub 10 | Scanner in = new Scanner(System.in); 11 | while(true){ 12 | long n=in.nextLong(); 13 | if(n<0) break; 14 | Stack stack= new Stack(); 15 | while(n>=3){ 16 | stack.push(n%3); 17 | n=n/3; 18 | } 19 | String sTernary=""+n; 20 | while(!(stack.isEmpty())) 21 | sTernary+=stack.pop(); 22 | System.out.println(sTernary); 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/uva/The3n1problem.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class The3n1problem { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | while(in.hasNextInt()){ 11 | int i = in.nextInt(); 12 | int j = in.nextInt(); 13 | int from = Math.min(i, j); 14 | int to = Math.max(i, j); 15 | int max = 0; 16 | 17 | for(int k=from; k<=to; k++){ 18 | max = Math.max(max, processCycle(k)); 19 | } 20 | 21 | System.out.println(i+" "+j+" "+max); 22 | } 23 | } 24 | 25 | static int processCycle(int n){ 26 | if(n == 1) 27 | return 1; 28 | else{ 29 | int cnt = 1; 30 | if(n%2!=0) 31 | return cnt += processCycle(3*n+1); 32 | else 33 | return cnt += processCycle(n/2); 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/uva/TheSnail.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TheSnail { 6 | 7 | public static void main(String[] args) { 8 | // TODO Auto-generated method stub 9 | Scanner in = new Scanner(System.in); 10 | int H, D, F, day; 11 | float U, height, fatigue; 12 | while(true) 13 | { 14 | H= in.nextInt(); 15 | if(H == 0) 16 | break; 17 | U=in.nextInt(); 18 | D=in.nextInt(); 19 | F=in.nextInt(); 20 | day = 1; 21 | height = 0; 22 | fatigue = U*F/100; 23 | while(true){ 24 | height += U; 25 | if(U > 0) 26 | U=U-fatigue; 27 | if(height > H){ 28 | System.out.printf("success on day %d%n",day); 29 | break; 30 | } 31 | height=height-D; 32 | if(height < 0){ 33 | System.out.printf("failure on day %d%n",day); 34 | break; 35 | } 36 | 37 | day++; 38 | } 39 | } 40 | 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/uva/TrainSwapping.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TrainSwapping { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | int t= in.nextInt(); 10 | while((t--)!=0){ 11 | int n= in.nextInt(); 12 | int[] a= new int[n]; 13 | for(int i=0;ia[j]) total++; 19 | } 20 | } 21 | System.out.printf("Optimal train swapping takes %d swaps.%n",total); 22 | 23 | } 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/uva/TrainTracks.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class TrainTracks { 8 | 9 | public static void main(String[] args) throws IOException { 10 | // TODO Auto-generated method stub 11 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 12 | int count,s,t = Integer.parseInt(in.readLine()); 13 | String line; 14 | while((t--)!=0) { 15 | count = 0; 16 | line = in.readLine(); 17 | s = line.length(); 18 | for(int i = 0; i < line.length(); i++) { 19 | if(line.charAt(i) == 'M') 20 | count++; 21 | if(line.charAt(i) == 'F') 22 | count--; 23 | } 24 | if(count==0 && s>2) 25 | System.out.println("LOOP"); 26 | else 27 | System.out.println("NO LOOP"); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/uva/TroublePentagon.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class TroublePentagon { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | double factor= Math.sin(108*Math.PI/180)/Math.sin(63*Math.PI/180); 10 | while(in.hasNext()){ 11 | double v= Double.parseDouble(in.next())*factor; 12 | System.out.printf("%.10f%n",v); 13 | } 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/uva/WERTYU.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.util.Scanner; 4 | 5 | public class WERTYU { 6 | 7 | public static void main(String[] args) { 8 | Scanner in = new Scanner(System.in); 9 | String keyboard= "`1234567890-=QWERTYUIOP[]\\ASDFGHJKL;'ZXCVBNM,./"; 10 | while(in.hasNext()){ 11 | String s= in.nextLine(); 12 | for(int i=0; i nums = new ArrayList(); 13 | while(in.hasNext()){ 14 | n= in.nextInt(); 15 | nums.add(n); 16 | Collections.sort(nums); 17 | size=nums.size(); 18 | if(size%2!=0) 19 | m=nums.get((size-1)/2); 20 | else 21 | m= (nums.get((size-1)/2) + nums.get(size/2))/2; 22 | System.out.println(m); 23 | } 24 | 25 | 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /src/uva/ZerosOnes.java: -------------------------------------------------------------------------------- 1 | package uva; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | import java.util.StringTokenizer; 7 | 8 | public class ZerosOnes { 9 | 10 | public static void main(String[] args) throws IOException { 11 | // TODO Auto-generated method stub 12 | BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); 13 | int n, a, b, temp,cont=1; 14 | boolean same; 15 | String s; 16 | StringTokenizer t = null; 17 | while ((s = in.readLine())!=null) 18 | { if(s.length()==0) 19 | break; 20 | n=Integer.parseInt(in.readLine()); 21 | System.out.printf("Case %d:%n",cont); 22 | for(int j=0;j