├── .gitattributes ├── .gitignore ├── .idea ├── .gitignore ├── Hackerrank.iml ├── inspectionProfiles │ └── Project_Default.xml ├── misc.xml ├── modules.xml └── vcs.xml ├── 10 Days of Statistics ├── Day 0 - Mean,Median and Mode.py ├── Day 0 - Weighted Mean.py ├── Day 1 - Interquartile Range.py ├── Day 1 - Quartiles.py ├── Day 1 - Standard Deviation.py ├── Day 2 - Basic Probability.py ├── Day 2 - Compound Event Probability.py ├── Day 2- More Dice.py ├── Day 3 - Cards of the Same Suit.py ├── Day 3 - Conditional Probability.py ├── Day 3 - Drawing Marbles.py ├── Day 4 - Binomial Distribution I.py ├── Day 4 - Binomial Distribution II.py ├── Day 4 - Geometric Distribution I.py ├── Day 4 - Geometric Distribution II.py ├── Day 5 - Normal Distribution I.py ├── Day 5 - Normal Distribution II.py ├── Day 5 - Poisson Distribution I.py ├── Day 5 - Poisson Distribution II.py ├── Day 6 - The Central Limit Theorem I.py ├── Day 6 - The Central Limit Theorem II.py ├── Day 6 - The Central Limit Theorem III.py ├── Day 7 - Pearson Correlation Coefficient I.py ├── Day 7 - Spearman's Rank Correlation Coefficient.py ├── Day 8 - Least Square Regression Line.py ├── Day 8 - Pearson Correlation Coefficient II.py └── Day 9 - Multiple Linear Regression.py ├── 1MonthPreparationKit ├── Week1 │ ├── 01PlusMinus.py │ ├── 02MiniMaxSum.py │ ├── 03TimeConservation.py │ ├── 04SparseArrays.py │ ├── 05LonelyInteger.py │ ├── 06FlippingBits.py │ ├── 07DiagonalDifference.py │ ├── 08CountingSort1.py │ ├── 09Pangrams.py │ ├── 10PermutingTwoArrays.py │ ├── 11SubarrayDivison1.py │ └── 12XORStrings2.py ├── Week2 │ ├── 01SalesbyMatch.py │ ├── 02ZigZagSequence.py │ ├── 03DrawingBook.py │ ├── 04TowerBreakers.py │ ├── 05CaesarCipher.py │ ├── 06MaxMin.py │ ├── 07DynamicArray.py │ ├── 08GridChallenge.py │ ├── 09PrimeDates.py │ ├── 10SherlockandArray.py │ ├── 11RecursiveDigitSum.py │ ├── 12CounterGame.py │ └── 13SumvsXOR.py ├── Week3 │ ├── 01TheBombermanGame.py │ ├── 02NewYearChaos.py │ ├── 03SherlockandtheValidString.py │ ├── 04ClimbingtheLeaderboard.py │ ├── 05ReverseaLinkedList.py │ ├── 06ReverseaDoublyLinkedList.py │ ├── 07InsertaNodeatASpecificPositioninaLinkedList.py │ ├── 08MergedTwoSortedLinkedLists.py │ ├── 09IceCreamParlor.py │ ├── 10QueueUsingTwoStacks.py │ ├── 11BalancedBrackets.py │ ├── 12Waiter.py │ └── 13SimpleTextEditor.py └── Week4 │ ├── 01EqualStacks.py │ ├── 02TheMaximumSubarray.py │ ├── 03LegoBlocks.py │ ├── 04QHEAP1.py │ ├── 05JesseandCookies.py │ ├── 06HackerlandRadioTransmitters.py │ ├── 07QuerieswithFixedLength.py │ ├── 08ArrayManipulation.py │ ├── 09HighestValuePalindrome.py │ ├── 10LilysHomework.py │ ├── 11TreePreorderTraversal.py │ ├── 12TreeHuffmanDecoding.py │ ├── 13BinarySearchTreeLowestCommonAncestor.py │ ├── 14NoPrefixSet.py │ ├── 15CastleontheGrid.py │ └── 16RoadsandLibraries.py ├── 30 Days of Challenge ├── Day 1 - Data Types.ipynb ├── Day 10 - Binary Numbers.ipynb ├── Day 11 - 2D Arrays.ipynb ├── Day 12 - Inheritance.ipynb ├── Day 13 - Abstract Classes.ipynb ├── Day 14 - Scope.ipynb ├── Day 15 - Linked List.ipynb ├── Day 16 - Exceptions - String to Integer.ipynb ├── Day 17 - More Exceptions.ipynb ├── Day 18 - Queues and Stacks.ipynb ├── Day 19 - Interfaces.ipynb ├── Day 2 - Operators.ipynb ├── Day 20 - Sorting.ipynb ├── Day 21 - Generics.java ├── Day 22 - Binary Search Trees.ipynb ├── Day 23 - BTS Level-Order Traversal.ipynb ├── Day 24 - More Linked List.ipynb ├── Day 25 - Running Time and Complexity.ipynb ├── Day 26 - Nested Logic.ipynb ├── Day 27 - Testing.ipynb ├── Day 29 - Bitwise AND.ipynb ├── Day 3 - Intro to Conditional Statements.ipynb ├── Day 4 - Class vs Instance.ipynb ├── Day 5 - Loops.ipynb ├── Day 6 - Let's Review.ipynb ├── Day 7 - Arrays.ipynb ├── Day 8 - Dictionaries and Maps.ipynb └── Day 9 - Recursion.ipynb ├── Algorithms ├── 01 - Warmup │ ├── A Very Big Sum.py │ ├── Birthday Cake Candles.py │ ├── Compare the Triples.py │ ├── Diagonal Difference.py │ ├── Mini - Max Sum.py │ ├── Plus Minus.py │ ├── Simple Array Sum.py │ ├── Solve Me First.py │ ├── Staircase.py │ └── Time Conversion.py ├── 02 - Implementation │ ├── 3D Surface Area.py │ ├── ACM ICPC Team.py │ ├── Absolute Permutation.py │ ├── Almost Sorted.py │ ├── Angry Professor.py │ ├── Append and Delete.py │ ├── Apple and Orange.py │ ├── Beatiful Days at the Movies.py │ ├── Between Two Sets.py │ ├── Beutiful Triplets.py │ ├── Bigger is Greater.py │ ├── Bill Divison.py │ ├── Breaking the Records.py │ ├── Cats and a Mouse.py │ ├── Cavity Map.py │ ├── Chocolate Feast.py │ ├── Circular Array Rotation.py │ ├── Climbing the Leaderboard.py │ ├── Cut the Sticks.py │ ├── Day of the Programmer.py │ ├── Designer PDF Viewer.py │ ├── Divisible Sum Pairs.py │ ├── Drawing Book.py │ ├── Electronics Shop.py │ ├── Ema's Supercomputer.py │ ├── Encryption.py │ ├── Equalize the Array.py │ ├── Extra Long Factorials.py │ ├── Fair Rations.py │ ├── Find Digits.py │ ├── Flatland Space Stations.py │ ├── Forming a Magic Square.py │ ├── Grading Students.py │ ├── Halloween Sale.py │ ├── Happy Ladybugs.py │ ├── Jumping on the Clouds - Revisited.py │ ├── Larry's Array.py │ ├── Library Fine.py │ ├── Lisa's Workbook.py │ ├── Manasa and Stones.py │ ├── Matrix Layer Rotation.py │ ├── Migratory Birds.py │ ├── Minimum Distances.py │ ├── Modified Kaprekar Numbers.py │ ├── Non - Divisible Subset.py │ ├── Number Line Jumps.py │ ├── Organizing Containers of Balls.py │ ├── Picking Numbers.py │ ├── Queen's Attack II.py │ ├── Save the Prisoner.py │ ├── Sequence Equation.py │ ├── Service Lane.py │ ├── Sherlock and Squares.py │ ├── Strange Counter.py │ ├── Subarray Division.py │ ├── Taum and B'day.py │ ├── The Bomberman Game.py │ ├── The Grid Search.py │ ├── The Hurdle Race.py │ ├── The Time in Words.py │ ├── Utopian Tree.py │ └── Viral Advertising.py ├── 03 - Strings │ ├── Anagram.py │ ├── Ashton and String.py │ ├── Bear and Steady Gene.py │ ├── Beautiful Binary String.py │ ├── Build a Palindrome.py │ ├── Build a String.py │ ├── Caesar Cipher.py │ ├── CamelCase.py │ ├── Cards Permutation.py │ ├── CircularPalindromes.java │ ├── Count Strings.py │ ├── Determining DNA Health.py │ ├── Find Strings.py │ ├── Funny String.py │ ├── Game of Thrones - I.py │ ├── Gemstones.py │ ├── Gridland Provinces.py │ ├── HackerRank in a String.py │ ├── Highest Value Palindrome.py │ ├── HowManySubstrings.java │ ├── LetterIslands.java │ ├── Making Anagrams.py │ ├── Mars Exploration.py │ ├── Maximum Palindromes.py │ ├── Morgan and a String.py │ ├── Palindrome Index.py │ ├── Palindromic Border.py │ ├── Pangrams.py │ ├── PseudoIsomorphicSubstrings.java │ ├── Save Humanity.py │ ├── Seperate the Numbers.py │ ├── SimilarStrings.java │ ├── String Construction.py │ ├── String Function Calculation.py │ ├── String Similarity.py │ ├── Strong Password.py │ ├── Super Functional Strings.py │ ├── Super Reduced String.py │ ├── The Love-Letter Mystery.py │ ├── Two Characters.py │ ├── Two Two.py │ ├── TwoStringsGame.java │ └── Weighted Uniform Strings.py ├── 04 - Sorting │ ├── Absolute Element Sums.py │ ├── Almost Integer Rock Garden.py │ ├── Big Sorting.py │ ├── Closest Numbers.py │ ├── Correctness and the Loop Invariant.py │ ├── Counting Sort 1.py │ ├── Counting Sort 2.py │ ├── Distant Pairs.py │ ├── Find the Median.py │ ├── Insertion Sort - Part 1.py │ ├── Insertion Sort - Part 2.py │ ├── Insertion Sort Advanced Analysis.py │ ├── Intro to Tutorial Challenges.py │ ├── King Richard's Knights.py │ ├── Lily's Homework.py │ ├── Quicksort 1 - Partition.py │ ├── Running Time of Algorithms.py │ ├── Similar Pair.py │ ├── Sorted Subsegments.py │ ├── Task Scheduling.py │ └── The Full Counting Sort.py ├── 05 - Search │ ├── Beautiful Quadruples.py │ ├── Bike Racers.py │ ├── Connected Cells in a Grid.py │ ├── Count Lock.py │ ├── Cut the Tree.py │ ├── Gena Playing Hanoi.py │ ├── Gridland Metro.py │ ├── Hackerland Radio Transmitters.py │ ├── Ice Cream Parlor.py │ ├── KnightL on a Chessboard.py │ ├── Maximing Mission Points.py │ ├── Minimum Loss.py │ ├── Missing Numbers.py │ ├── Red Kinght's Shortest Path.py │ ├── Sherlock and Array.py │ └── Short Palindrome.py └── 06 - Graph Theory │ ├── Breadth First Search - Shortest Reach.py │ ├── Dijkstra - Shortest Reach 2.py │ ├── Even Tree.py │ ├── Journey to the Moon.py │ ├── Kruskal (MST) - Really Special Subtree.py │ ├── Snakes and Ladders - The Quickest Way Up.py │ ├── Subset Component.py │ └── Synchronous Shopping.py ├── Artificial Intelligence └── 01 - Bot Building │ ├── Battleship 1 Player.py │ ├── Bot Clean.py │ ├── Bot saves Princes - 2.py │ ├── Bot saves Princess.py │ ├── BotClean Large.py │ ├── BotClean Partially Observable.py │ ├── BotClean Stochastic.py │ ├── Maze Escape.py │ └── test.txt ├── Badges ├── 10_days_of_statistics_5_star.png ├── 30-days-of-code_5_star.png ├── SQL_adv_badge.png ├── c#_basic_skill.png ├── java_5_star.png ├── java_basic_skill.png ├── problem-solving_stars_5.png ├── problem-solving_stars_6.png ├── problem_solving_basic_skill.png ├── problem_solving_intermediate_skill.png ├── python_5_star.png ├── python_basic_skill.png ├── r_int_badge.png ├── se_badge.png ├── se_intern_badge.png ├── sql_5_star.png ├── sql_basic_skill.png └── sql_intermediate_skill.png ├── C++ └── 01 - Introduction │ └── Input and Output.cpp ├── Data Structures ├── 01 - Arrays │ ├── 2D Array - DS.py │ ├── Array Manipulation.py │ ├── Arrays - DS.py │ ├── Dynamic Array.py │ ├── Left Rotation.py │ └── Sparse Arrays.py └── 02 - Linked Lists │ ├── Compare two linked lists.py │ ├── Cycle Detection.py │ ├── Delete a node.py │ ├── Delete duplicate-value nodes from a sorted linked list.py │ ├── Get Node Value.py │ ├── Insert a Node at the Tail of a Linked List.py │ ├── Insert a node at the head of a linked list.py │ ├── Merge two sorted linked lists.py │ ├── Print in Reverse.py │ ├── Print the Elements of a Linked List.py │ └── Reverse a linked list.py ├── Java ├── 1 - Introduction │ ├── If Else │ │ └── Solution.java │ ├── Java Currency Formatter │ │ └── Solution.java │ ├── Java Datatypes │ │ └── Solution.java │ ├── Java Date and Time │ │ └── Solution.java │ ├── Java End of File │ │ └── Solution.java │ ├── Java Int to String │ │ └── Solution.java │ ├── Java Loop I │ │ └── Solution.java │ ├── Java Loops II │ │ └── Solution.java │ ├── Java Output Formatting │ │ └── Solution.java │ ├── Java Static Initializer Block │ │ └── Solution.java │ ├── Java Stdin and Stdout I │ │ └── Solution.java │ └── Java Stdin and Stdout II │ │ └── Solution.java ├── 2 - String │ ├── Java Anagrams │ │ └── Solution.java │ ├── Java Regex 2 - Duplicate Words │ │ └── DuplicateWords.java │ ├── Java Regex │ │ └── Solution.java │ ├── Java String Reverse │ │ └── Solution.java │ ├── Java String Tokens │ │ └── Solution.java │ ├── Java Strings Introduction │ │ └── Solution.java │ ├── Java Substring Comparisons │ │ └── Solution.java │ ├── Java Substring │ │ └── Solution.java │ ├── Pattern Syntax Checker │ │ └── Solution.java │ ├── Tag Content Extractor │ │ └── Solution.java │ └── Valid Username Regular Expression │ │ └── Solution.java ├── 3 - BigNumber │ ├── Java BigDecimal │ │ └── Solution.java │ ├── Java BigInteger │ │ └── Solution.java │ └── Java Primality Test │ │ └── Solution.java ├── 4 - Data Structures │ ├── Java 1D Array (Part 2) │ │ └── Solution.java │ ├── Java 1D Array │ │ └── Solution.java │ ├── Java 2D Array │ │ └── Solution.java │ ├── Java Arraylist │ │ └── Solution.java │ ├── Java BitSet │ │ └── Solution.java │ ├── Java Comparator │ │ └── Solution.java │ ├── Java Dequeue │ │ └── Solution.java │ ├── Java Generics │ │ └── Solution.java │ ├── Java Hashset │ │ └── Solution.java │ ├── Java List │ │ └── Solution.java │ ├── Java Map │ │ └── Solution.java │ ├── Java Priority Queue │ │ └── Solution.java │ ├── Java Sort │ │ └── Solution.java │ ├── Java Stack │ │ └── Solution.java │ ├── Java Subarray │ │ └── Solution.java │ └── out │ │ └── production │ │ └── Data Structures │ │ └── Solution.class ├── 5 - Object Oriented Programming │ ├── Java Abstract Class │ │ └── Solution.java │ ├── Java Inheritance I │ │ └── Solution.java │ ├── Java Inheritance II │ │ └── Solution.java │ ├── Java Instanceof keyword │ │ └── Solution.java │ ├── Java Interface │ │ └── Solution.java │ ├── Java Iterator │ │ └── Solution.java │ ├── Java Method Overriding 2 (Super Keyword) │ │ └── Solution.java │ └── Java Method Overriding │ │ └── Solution.java ├── 6 - Exception Handling │ ├── Java Exception Handling (Try - Catch) │ │ └── Solution.java │ └── Java Exception Handling │ │ └── Solution.java └── 7 - Advanced │ ├── .idea │ ├── .gitignore │ ├── misc.xml │ ├── modules.xml │ └── vcs.xml │ ├── 7 - Advanced.iml │ ├── Can You Access │ └── Solution.java │ ├── Covariant Return Types │ └── Solution.java │ ├── Java Annotations │ └── Solution.java │ ├── Java Factory Pattern │ └── Solution.java │ ├── Java Lamba Expressions │ └── Solution.java │ ├── Java MD5 │ └── Solution.java │ ├── Java Reflection - Attributes │ └── Solution.java │ ├── Java SHA - 256 │ └── Solution.java │ ├── Java Singleton Pattern │ └── Singleton.java │ ├── Java Vararggs - Simple Addition │ └── Solution.java │ ├── Java Visitor Pattern │ └── Solution.java │ └── Prime Checker │ └── Solution.java ├── LICENSE ├── ProjectEuler ├── 01-Multiplesof3and5.py ├── 02-EvenFibonacciNumbers.py ├── 03-LargestPrimeFactor.py ├── 04-LargestPalindromeProduct.py ├── 05-SmallestMultiple.py ├── 06-SumSquareDifference.py ├── 07-10001stPrime.py ├── 08-LargestProductinaSeries.py ├── 09-SpecialPythagoreanTriplet.py ├── 10-SummationOfPrimes.py ├── 11-LargestProductInAGrid.py ├── 12-HighlyDivisibleTriangularNumber.py ├── 13-LargeSum.py ├── 14-LongestCollatzSequence.py ├── 15-LatticePaths.py ├── 16-PowerDigitSum.py ├── 17-NumberToWords.py ├── 18-MaximumPathSum1.py └── 19-CountingSundays.py ├── Python ├── 01 - Introduction │ ├── Arithmetic Operators.py │ ├── Loops.py │ ├── Print a function.py │ ├── Python - Divison.py │ ├── Python If-Else.py │ └── Write a function.py ├── 02 - Basic Data Types │ ├── Find the Maximum Depth.py │ ├── Finding the percentage.py │ ├── List Comprehesion.py │ ├── Lists.py │ ├── Nested Lists.py │ └── Tuples.py ├── 03 - Strings │ ├── Alphabet Rangoli.py │ ├── Capitalize.py │ ├── Designer Door Mat.py │ ├── Find a string.py │ ├── Merge the Tools.py │ ├── Mutations.py │ ├── String Formatting.py │ ├── String Split and Join.py │ ├── String Validators.py │ ├── Text Alignment.py │ ├── Text Wrap.py │ ├── The Minion Game.py │ ├── What's your name.py │ └── sWAP cASE.py ├── 04 - Sets │ ├── Introductiont to Sets.py │ ├── No Idea.py │ ├── Set - Mutations.py │ ├── Set - add().py │ ├── Set - difference().py │ ├── Set - discard() - remove() , pop().py │ ├── Set - intersection().py │ ├── Set - symmetric_difference().py │ ├── Set - union() Operation.py │ └── Symmetric Difference.py ├── 05 - Math │ ├── Find Angle MBC.py │ ├── Integers Come In All Sizes.py │ ├── Mod Divmod.py │ ├── Polar Coordinates.py │ └── Power - Mod Power.py ├── 06 - Itertools │ ├── itertools.permutations().py │ └── itertools.product().py ├── 07 - Collections │ ├── Collections.OrderedDict().py │ ├── Collections.deque().py │ ├── Collections.namedtuple().py │ ├── Company Logo.py │ ├── DefaultDict Tutorial.py │ ├── Piling Up!.py │ ├── Word Order.py │ └── collections.Counter().py ├── 08 - Data and Time │ ├── Calendar Module.py │ └── Time Delta.py ├── 09 - Errors and Exceptions │ ├── Exceptions.py │ └── Incorrect Regex.py ├── 10 - Classes │ ├── Class 2 - Find the Torsional Angle.py │ └── Classes - Dealing with Complex Numbers.py ├── 12 - Python Functionals │ ├── Map and Lambda Function.py │ ├── Reduce Function.py │ └── Validating Email Addressess with a Filter.py ├── 13 - Regex and Parsing │ ├── Detect Floating Point Number.py │ ├── Detect HTML Tags, Attributes and Attribute Values.py │ ├── Group(), Groups() - Groupdict().py │ ├── HTML Parser - Part 1.py │ ├── HTML Parser - Part 2.py │ ├── Hex Color Code.py │ ├── Matrix Script.py │ ├── Re.findall - Re.finditer().py │ ├── Re.split().py │ ├── Re.start() - Re.end().py │ ├── Regex Substitution.py │ ├── Validating Credit Card Numbers.py │ ├── Validating Postal Codes.py │ ├── Validating Roman Numerals.py │ ├── Validating UID.py │ ├── Validating and Parsing Email Addresses.py │ └── Validating phone numbers.py ├── 14 - XML │ ├── XML 1 - Find the Score.py │ └── XML 2 - Find the Maximum Depth.py ├── 15 - Closures and Decorators │ ├── Decorators 2 - Name Directory.py │ └── Standardize Mobile Number Using Decorators.py ├── 16 - NumPy │ ├── Array Mathematics.py │ ├── Arrays.py │ ├── Concatenate.py │ ├── Dot and Cross.py │ ├── Eye and Identity.py │ ├── Floor, Ceil and Rint.py │ ├── Inner and Outer.py │ ├── Linear Algebra.py │ ├── Mean, Var, and Std.py │ ├── Min and Max.py │ ├── Polynomials.py │ ├── Shape and Reshape.py │ ├── Sum and Prod.py │ ├── Transpose and Flatten.py │ └── Zeros and Ones.py └── 17 - Debugging │ ├── Default Arguments.py │ └── Words Score.py ├── README.md ├── SQL ├── Advanced Join │ ├── 15 Days of Learning SQL.sql │ ├── Interviews.sql │ ├── Placements.sql │ ├── SQL Project Planning.sql │ └── Symmetric Pairs.sql ├── Advanced Select │ ├── Binary Tree Nodes.sql │ ├── New Companies.sql │ ├── Occupations.sql │ ├── The PADS.sql │ └── Type of Triangle.sql ├── Aggregation │ ├── Average Population.sql │ ├── Japan Population.sql │ ├── Population Density Difference.sql │ ├── Revising Aggregations - Averages.sql │ ├── Revising Aggregations - The Count Function.sql │ ├── Revising Aggregations - The Sum Function.sql │ ├── The Blunder.sql │ ├── Top Earners.sql │ ├── Weather Observation Station 13.sql │ ├── Weather Observation Station 14.sql │ ├── Weather Observation Station 15.sql │ ├── Weather Observation Station 16.sql │ ├── Weather Observation Station 17.sql │ ├── Weather Observation Station 18.sql │ ├── Weather Observation Station 19.sql │ ├── Weather Observation Station 2.sql │ └── Weather Observation Station 20.sql ├── Alternative Queries │ ├── Draw The Triangle 1.sql │ ├── Draw The Triangle 2.sql │ └── Print Prime Numbers.sql ├── Basic Join │ ├── African Cities.sql │ ├── Average Population of Each Continent.sql │ ├── Challenges.sql │ ├── Contest Leaderboard.sql │ ├── Ollivanders Inventory.sql │ ├── Population Census.sql │ ├── The Report.sql │ └── Top Competitors.sql └── Basic Select │ ├── EmployeeNames.sql │ ├── EmployeeSalaries.sql │ ├── HigherThan75Marks.sql │ ├── JapaneseCitiesAttributes.sql │ ├── JapaneseCitiesNames.sql │ ├── RevisingtheSelectQuery1.sql │ ├── RevisingtheSelectQuery2.sql │ ├── WeatherObservationStation1.sql │ ├── WeatherObservationStation10.sql │ ├── WeatherObservationStation11.sql │ ├── WeatherObservationStation12.sql │ ├── WeatherObservationStation3.sql │ ├── WeatherObservationStation4.sql │ ├── WeatherObservationStation5.sql │ ├── WeatherObservationStation6.sql │ ├── WeatherObservationStation7.sql │ ├── WeatherObservationStation8.sql │ └── WeatherObservationStation9.sql ├── Skills Certification Test ├── Java (Basic) │ └── The Adder Class │ │ └── Solution.java ├── Problem Solving (Basic) │ ├── Active Traders.py │ └── Maximum Cost of Laptop Count.py ├── Problem Solving (Intermediate) │ ├── Bitwise AND.PY │ └── User Friendly Password System.py ├── R (Intermediate) │ ├── FizzBuzz.r │ └── MortgageCompetitiveIndex.r ├── SQL (Advanced) │ ├── count_the_employess.sql │ ├── weather_analysis.sql │ └── weekend_hours_worked.sql ├── Software Engineer Intern │ ├── Growthin2Dimensions.py │ └── YoungestEmployees.sql └── Software Engineer │ ├── ConferenceSchedule.py │ ├── RestAPIProductsInRange.py │ └── ThePerfectArrangement.sql ├── Skills Certification ├── Java (Basic).png ├── Problem Solving (Basic).png ├── Problem Solving (Intermediate).png ├── Python (Basic) Certificate.png ├── R (Intermediate).png ├── SQL (Advanced).png ├── SQL (Basic) Certificate.png ├── SQL (Intermediate).png ├── Software Engineer Intern.png └── Software Engineer.png └── The HackerRank Interview Preparation Kit ├── 01 - Warm-up Challenges ├── Counting Valleys.py ├── Jumping on the Clouds.py ├── Repeated String.py └── Sales by Match.py ├── 02 - Arrays ├── 2D Array - DS.py ├── Array Manipulatioon.py ├── Arrays - Left Rotation.py ├── Minimum Swaps 2.py └── New Year Chaos.py ├── 03 - Dictionaries and Hashmaps ├── Count Triplets.py ├── Frequency Queries.py ├── Hash Tables - Ransom Note.py ├── Sherlock and Anagrams.py └── Two Strings.py ├── 04 - Sorting ├── Fradulent Activity Notifications.py ├── Mark and Toys.py ├── Merge Sort- Counting Inversions.py ├── Sorting - Bubble Sort.py └── Sorting - Comparator.py ├── 05 - String Manipulation ├── Alternating Characters.py ├── Common Child.py ├── Sherlock and the Valid String.py ├── Special String Again.py └── Strings- Making Anagrams.py ├── 06 - Greedy Algorithms ├── Greedy Florist.py ├── Luck Balance.py ├── Max Min.py ├── Minimum Absolute Difference in an Array.py └── Reverse Shuffle Merge.py ├── 07 - Search ├── Hash Tables - Ice Cream Parlor.py ├── Making Candles.py ├── Maximum Subarray Sum.py ├── Minimum Time Required.py ├── Pairs.py ├── Swap Nodes [Algo].py └── Triple Sum.py ├── 08 - Dynamic Programming ├── Abbreviation.py ├── Candies.py ├── Decibinary Numbers.py └── Max Array Sum.py ├── 09 - Stacks and Queues ├── Balanced Brackets.py ├── Castle on the Grid.py ├── Largest Rectangle.py ├── Min Max Riddle.py ├── Posionous Plants.py └── Queues - A Tale of Two Stacks.py ├── 10 - Graphs ├── BFS - Shortest Rearch in a Graph.py ├── DFS - Connected Cell in a Grid.py ├── Find the nearest clone.py ├── Matrix.py └── Roads and Libraries.py ├── 11 - Trees ├── Balanced Forest.py ├── Binary Search Tree - Loweats Common Ancestor.py ├── Tree - Height of a Binary Tree.py ├── Tree - Huffman Decoding.py └── Trees - Is this a Binary Search Tree.py ├── 12 - Linked Lists ├── Find Merge Point of Two Lists.py ├── Insert a node at specific position in a linked list.py ├── Inserting a Node Into a Sorted Doubly Linked List.py ├── Linked Lists - Detect a cycle.py └── Reverse a doubly linked list.py ├── 13 - Recursion and Backtracking ├── Crossword Puzzle.py ├── Recursion - Davis Staircase.py ├── Recursion - Fibonacci Numbers.py └── Recursive Digit Sum.py └── 14 - Miscellaneous ├── Flipping bits.py ├── Friend Circle Queries.py ├── Maximum Xor.py └── Time Complexity - Primality.py /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sql linguist-detectable=true 2 | *.sql linguist-language=sql 3 | *.sql text 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea/inspectionProfiles/Project_Default.xml 3 | *.xml 4 | *.pdf 5 | 6 | 7 | 1MonthPreparationKit/Week1/MockInterview/13MockTest1.py 8 | 1MonthPreparationKit/Week1/MockInterview/14MockTest2.py 9 | 1MonthPreparationKit/Week2/MockInterview/14MockTest1.py 10 | 1MonthPreparationKit/Week2/MockInterview/15MockTest2.py 11 | 1MonthPreparationKit/Week2/MockInterview/16MockText3.py 12 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /.idea/Hackerrank.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 0 - Mean,Median and Mode.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | import numpy as np 3 | from scipy.stats import stats 4 | 5 | size = int(input()) 6 | numbers = list(map(int, input().split())) 7 | print(np.mean(numbers)) 8 | print(np.median(numbers)) 9 | print(int(stats.mode(numbers)[0])) 10 | 11 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 0 - Weighted Mean.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'weightedMean' function below. 11 | # 12 | # The function accepts following parameters: 13 | # 1. INTEGER_ARRAY X 14 | # 2. INTEGER_ARRAY W 15 | # 16 | 17 | def weightedMean(n, X, W): 18 | # Write your code here 19 | sum_items = 0 20 | for i in range(n): 21 | sum_items = sum_items + (X[i] * W[i]) 22 | 23 | print("{:.1f}".format(sum_items / sum(W))) 24 | 25 | 26 | if __name__ == '__main__': 27 | n = int(input().strip()) 28 | vals = list(map(int, input().rstrip().split())) 29 | weights = list(map(int, input().rstrip().split())) 30 | weightedMean(n, vals, weights) 31 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 1 - Standard Deviation.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'stdDev' function below. 12 | # 13 | # The function accepts INTEGER_ARRAY arr as parameter. 14 | # 15 | 16 | def stdDev(arr): 17 | # Print your answers to 1 decimal place within this function 18 | n = len(arr) 19 | mean = sum(arr) / n 20 | variance = sum([((index - mean) ** 2) for index in arr]) / n 21 | std = math.sqrt(variance) 22 | 23 | print("{:.1f}".format(std)) 24 | 25 | 26 | if __name__ == '__main__': 27 | n = int(input().strip()) 28 | 29 | vals = list(map(int, input().rstrip().split())) 30 | 31 | stdDev(vals) 32 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 2 - Basic Probability.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 2: Basic Probability 3 | 4 | Author: Eda AYDIN 5 | 6 | P_event = #evet_outcomes / #total_outcomes 7 | 8 | """ 9 | import itertools 10 | 11 | dice_outcomes = [1, 2, 3, 4, 5, 6] 12 | total_experiment_outcomes = list(itertools.product(dice_outcomes, repeat=2)) 13 | favorable_experiment_outcomes = [sum(outcome) for outcome in total_experiment_outcomes 14 | if sum(outcome) <= 9] 15 | 16 | print("{} / {}".format(len(favorable_experiment_outcomes), len(total_experiment_outcomes))) 17 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 2 - Compound Event Probability.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 2: Compound Event Probability 3 | 4 | Author: Eda AYDIN 5 | 6 | """ 7 | import itertools 8 | from collections import Counter 9 | from fractions import Fraction 10 | 11 | X = list(Counter({0: 4, 1: 3}).elements()) 12 | Y = list(Counter({0: 5, 1: 4}).elements()) 13 | Z = list(Counter({0: 4, 1: 4}).elements()) 14 | 15 | total_experiment_outcomes = list(itertools.product(X, Y, Z)) 16 | favorable_experiment_outcomes = sum([sum(i) == 1 for i in total_experiment_outcomes]) 17 | 18 | print(Fraction(favorable_experiment_outcomes, len(total_experiment_outcomes))) 19 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 2- More Dice.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 2: More Dice 3 | 4 | Author: Eda AYDIN 5 | 6 | """ 7 | import itertools 8 | 9 | dice_outcomes = [1, 2, 3, 4, 5, 6] 10 | total_experiment_outcomes = list(itertools.product(dice_outcomes, repeat=2)) 11 | favorable_experiment_outcomes = list((x, y) for x, y in itertools.product(dice_outcomes, repeat=2) if x != y) 12 | favorable_experiment_outcomes = [sum(outcome) for outcome in favorable_experiment_outcomes 13 | if sum(outcome) == 6] 14 | 15 | print("{} / {}".format(len(favorable_experiment_outcomes), len(total_experiment_outcomes))) 16 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 3 - Cards of the Same Suit.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 3 - Cards of the Same Suit 3 | 4 | Author: Eda AYDIN 5 | """ 6 | import itertools 7 | 8 | # You draw 2 cars from a standard 52-card deck without replacing them. 9 | from fractions import Fraction 10 | 11 | total_experiment_outcomes = 52 12 | suit_number = 4 13 | 14 | for_each_suite_number = total_experiment_outcomes / suit_number 15 | 16 | first_card = Fraction(int(for_each_suite_number), total_experiment_outcomes) 17 | second_card = Fraction(int(for_each_suite_number) - 1, total_experiment_outcomes - 1) 18 | 19 | result = first_card * second_card * suit_number 20 | 21 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 3 - Drawing Marbles.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 3: Drawing Marbles 3 | 4 | A bag contains 3 red marbles and 4 blue marbles. Then, 2 marbles are drawn from the bag, at random, without 5 | replacement. If the first marble drawn is red, what is the probability that second marble is blue? 6 | 7 | Author: Eda AYDIN 8 | """ 9 | 10 | import itertools 11 | from collections import Counter 12 | 13 | from fractions import Fraction 14 | 15 | # X : bag, 0 : red marbles, 1 : blue marbles 16 | X = list(Counter({0: 3, 1: 4}).elements()) 17 | 18 | total_experiment_outcomes = itertools.permutations(X, 2) 19 | 20 | first_draw = list(i for i in total_experiment_outcomes if i[0] == 0) 21 | 22 | second_draw = list(i for i in first_draw if i[1] == 1) 23 | 24 | result = Fraction(len(second_draw), len(first_draw)) 25 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 4 - Geometric Distribution I.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 4: Geometric Distribution I 3 | 4 | The probability that a machine produces a defective product is 1/3. What is the 5 | probability that the 1st defect occurs that 5th item produced? 6 | 7 | Author: Eda AYDIN 8 | 9 | """ 10 | 11 | 12 | def geometric(n, p): 13 | q = 1 - p 14 | return q ** (n - 1) * p 15 | 16 | 17 | probability = list(map(int, input().split())) 18 | p = probability[0] / probability[1] 19 | n = int(input()) 20 | 21 | print(round(geometric(n, p), 3)) 22 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 4 - Geometric Distribution II.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 4: Geometric Distribution II 3 | 4 | The probability that a machine produces a defective product is 1/3. What is the 5 | probability that the 1st defect is found during the first 5 inspections? 6 | 7 | Author: Eda AYDIN 8 | 9 | """ 10 | 11 | 12 | def geometric(n, p): 13 | result = 0 14 | q = 1 - p 15 | for i in range(n + 1): 16 | if i > 0: 17 | result += (q ** (i - 1) * p) 18 | 19 | return result 20 | 21 | 22 | probability = list(map(int, input().split())) 23 | p = probability[0] / probability[1] 24 | n = int(input()) 25 | 26 | print(round(geometric(n, p), 3)) 27 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 5 - Poisson Distribution I.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 5: Poisson Distribution I 3 | 4 | A random variable,X, follows Poisson distribution with mean of 2.5. 5 | Find the probability with which the random variable X is equal to 5. 6 | 7 | Author: Eda AYDIN 8 | 9 | """ 10 | 11 | 12 | def factorial(n): 13 | if n == 1 or n == 0: 14 | return 1 15 | if n > 1: 16 | return factorial(n - 1) * n 17 | 18 | 19 | def poisson(k, lambda1): 20 | e = 2.71828 21 | poisson_distribution = (lambda1 ** k) * (e ** -lambda1) / factorial(k) 22 | return poisson_distribution 23 | 24 | 25 | lambda1 = float(input()) 26 | k = float(input()) 27 | 28 | print(round(poisson(k, lambda1), 3)) 29 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 5 - Poisson Distribution II.py: -------------------------------------------------------------------------------- 1 | """ 2 | Day 5: Poisson Distribution I 3 | 4 | A random variable,X, follows Poisson distribution with mean of 2.5. 5 | Find the probability with which the random variable X is equal to 5. 6 | 7 | Author: Eda AYDIN 8 | 9 | """ 10 | 11 | 12 | def poisson(lambdas): 13 | for i in range(len(lambdas)): 14 | if lambdas[i] == 0.88: 15 | print(round(160 + 40 * (lambdas[i] + lambdas[i] ** 2), 3)) 16 | if lambdas[i] == 1.55: 17 | print(round(128 + 40 * (lambdas[i] + lambdas[i] ** 2), 3)) 18 | 19 | 20 | lambdas = list(map(float, input().split())) 21 | poisson(lambdas) 22 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 6 - The Central Limit Theorem I.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-1/ 3 | 4 | Author: Eda AYDIN 5 | """ 6 | 7 | import math 8 | 9 | max_height = int(input()) 10 | number_of_boxes = int(input()) 11 | mean_weight_of_cargo_box = int(input()) 12 | std = int(input()) 13 | 14 | print(round(0.5 * (1 + math.erf((max_height - (number_of_boxes * mean_weight_of_cargo_box)) / 15 | ((math.sqrt(number_of_boxes) * std) * math.sqrt(2)))), 4)) 16 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 6 - The Central Limit Theorem II.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-2 3 | 4 | Author: Eda AYDIN 5 | """ 6 | import math 7 | 8 | tickets = int(input()) 9 | students = int(input()) 10 | mean = float(input()) 11 | stdev = float(input()) 12 | 13 | mu = students * mean 14 | standard_deviation = math.sqrt(100) * stdev 15 | 16 | 17 | # mu : mean of the distribution 18 | # sigma^2: variance 19 | # sigma: standard deviation 20 | 21 | def normal_distribution(x, mu, stdev): 22 | return 1 / 2 * (1 + math.erf((x - mu) / (stdev * math.sqrt(2)))) 23 | 24 | 25 | print(round(normal_distribution(tickets, mu, standard_deviation), 4)) 26 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 6 - The Central Limit Theorem III.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem:https://www.hackerrank.com/challenges/s10-the-central-limit-theorem-3 3 | 4 | Author: Eda AYDIN 5 | """ 6 | 7 | import math 8 | 9 | sample_size = int(input()) 10 | mean = int(input()) 11 | stdev = int(input()) 12 | distribution_percentage = float(input()) 13 | z = float(input()) 14 | 15 | print(round(-1.96 * (stdev / math.sqrt(sample_size)) + mean, 2)) 16 | print(round(1.96 * (stdev / math.sqrt(sample_size)) + mean, 2)) 17 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 7 - Pearson Correlation Coefficient I.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/s10-pearson-correlation-coefficient/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | import statistics 7 | 8 | n = int(float(input())) 9 | dataset_X = list(map(float, input().split())) 10 | dataset_Y = list(map(float, input().split())) 11 | 12 | 13 | def pearson_correlation(n, dataset_x, dataset_y): 14 | mean_x = statistics.mean(dataset_x) 15 | mean_y = statistics.mean(dataset_y) 16 | std_x = statistics.pstdev(dataset_x) 17 | std_y = statistics.pstdev(dataset_y) 18 | summation = 0 19 | 20 | for i in range(n): 21 | summation += (dataset_x[i] - mean_x) * (dataset_y[i] - mean_y) 22 | 23 | return summation / (n * std_x * std_y) 24 | 25 | 26 | print(round(pearson_correlation(n, dataset_X, dataset_Y), 3)) 27 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 8 - Least Square Regression Line.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/s10-least-square-regression-line/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | 7 | 8 | def mean(X): 9 | return sum(X) / len(X) 10 | 11 | 12 | def leastSquareRegression(X, Y): 13 | b = sum([(X[i] - mean(X)) * (Y[i] - mean(Y)) 14 | for i in range(len(X))]) / sum([(j - mean(X)) ** 2 for j in X]) 15 | a = mean(Y) - (b * mean(X)) 16 | return a + (b * 80) 17 | 18 | 19 | X = [] 20 | Y = [] 21 | for i in range(5): 22 | x, y = list(map(int, input().split())) 23 | X.append(x) 24 | Y.append(y) 25 | 26 | print(round(leastSquareRegression(X, Y), 3)) 27 | -------------------------------------------------------------------------------- /10 Days of Statistics/Day 8 - Pearson Correlation Coefficient II.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/s10-mcq-7/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | import math 7 | import statistics 8 | import sympy 9 | import fractions 10 | 11 | x, y = sympy.symbols('x y') 12 | 13 | eq1 = sympy.Eq(3*x + 4*y + 8) 14 | eq2 = sympy.Eq(4*x + 3*y + 7) 15 | 16 | m1 = fractions.Fraction(-3/4) 17 | m2 = fractions.Fraction(-3/4) 18 | 19 | p2 = fractions.Fraction(math.sqrt(m1 * m2)) 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /1MonthPreparationKit/Week1/02MiniMaxSum.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'miniMaxSum' function below. 11 | # 12 | # The function accepts INTEGER_ARRAY arr as parameter. 13 | # Give five positive integers, find the minimum and maximum values that can be calculated bu summing exactly four of the five integers. Then print the respective minimum and maximum values as a single line of two space-separated long integers. 14 | # 15 | 16 | def miniMaxSum(arr): 17 | arr.sort() 18 | minSum = sum(arr[:4]) 19 | maxSum = sum(arr[-4:]) 20 | print(minSum, maxSum) 21 | 22 | if __name__ == '__main__': 23 | arr = list(map(int, input().rstrip().split())) 24 | miniMaxSum(arr) 25 | -------------------------------------------------------------------------------- /1MonthPreparationKit/Week1/03TimeConservation.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | from datetime import datetime 9 | 10 | # 11 | # Complete the 'timeConversion' function below. 12 | # Given a time in 12-hour AM/PM format, convert it to military (24-hour) time. 13 | # The function is expected to return a STRING. 14 | # The function accepts STRING s as parameter. 15 | # 16 | 17 | def timeConversion(s): 18 | # Convert the input time string to a datetime object 19 | time_obj = datetime.strptime(s, '%I:%M:%S%p') 20 | 21 | # Convert the datetime object to military time format 22 | military_time = time_obj.strftime('%H:%M:%S') 23 | 24 | return military_time 25 | if __name__ == '__main__': 26 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 27 | 28 | s = input() 29 | 30 | result = timeConversion(s) 31 | 32 | fptr.write(result + '\n') 33 | 34 | fptr.close() 35 | -------------------------------------------------------------------------------- /1MonthPreparationKit/Week1/05LonelyInteger.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'lonelyinteger' function below. 11 | # Given an array of integers, where all elements but one occur twice, find the unique element. 12 | # The function is expected to return an INTEGER. 13 | # The function accepts INTEGER_ARRAY a as parameter. 14 | # 15 | 16 | def lonelyinteger(a): 17 | # Write your code here 18 | # Iterate through the list of integers 19 | for number in a: 20 | # If the number occurs only once in the list, return it 21 | if a.count(number) == 1: 22 | # Return the number 23 | return number 24 | 25 | if __name__ == '__main__': 26 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 27 | 28 | n = int(input().strip()) 29 | 30 | a = list(map(int, input().rstrip().split())) 31 | 32 | result = lonelyinteger(a) 33 | 34 | fptr.write(str(result) + '\n') 35 | 36 | fptr.close() 37 | -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/A Very Big Sum.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'aVeryBigSum' function below. 11 | # 12 | # The function is expected to return a LONG_INTEGER. 13 | # The function accepts LONG_INTEGER_ARRAY ar as parameter. 14 | # 15 | 16 | def aVeryBigSum(ar): 17 | # Write your code here 18 | return sum(ar) 19 | 20 | if __name__ == '__main__': 21 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 22 | 23 | ar_count = int(input().strip()) 24 | 25 | ar = list(map(int, input().rstrip().split())) 26 | 27 | result = aVeryBigSum(ar) 28 | 29 | fptr.write(str(result) + '\n') 30 | 31 | fptr.close() 32 | -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/Birthday Cake Candles.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'birthdayCakeCandles' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts INTEGER_ARRAY candles as parameter. 14 | # 15 | 16 | def birthdayCakeCandles(candles): 17 | # Write your code here 18 | maximum = max(candles) 19 | count = 0 20 | for i in range(0, len(candles)): 21 | if candles[i] == maximum: 22 | count += 1 23 | return count 24 | 25 | 26 | if __name__ == '__main__': 27 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 28 | 29 | candles_count = int(input().strip()) 30 | 31 | candles = list(map(int, input().rstrip().split())) 32 | 33 | result = birthdayCakeCandles(candles) 34 | 35 | fptr.write(str(result) + '\n') 36 | 37 | fptr.close() 38 | -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/Mini - Max Sum.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'miniMaxSum' function below. 11 | # 12 | # The function accepts INTEGER_ARRAY arr as parameter. 13 | # 14 | 15 | def miniMaxSum(arr): 16 | # Write your code here 17 | arr.sort() 18 | summation = [None]*int(len(arr)-3) 19 | for i in range(0, len(arr)-3): 20 | total = 0 21 | for j in range (i, i+4): 22 | total += arr[j] 23 | summation[i] = total 24 | 25 | print(summation[0],summation[-1]) 26 | 27 | if __name__ == '__main__': 28 | 29 | arr = list(map(int, input().rstrip().split())) 30 | 31 | miniMaxSum(arr) 32 | -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/Plus Minus.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'plusMinus' function below. 11 | # 12 | # The function accepts INTEGER_ARRAY arr as parameter. 13 | # 14 | 15 | def plusMinus(arr): 16 | # Write your code here 17 | positive, negative, zero = 0, 0, 0 18 | 19 | for i in range(0, len(arr)): 20 | if arr[i] > 0: 21 | positive += 1 22 | elif arr[i] < 0: 23 | negative += 1 24 | elif arr[i] == 0: 25 | zero += 1 26 | 27 | print(positive / len(arr)) 28 | print(negative / len(arr)) 29 | print(zero / len(arr)) 30 | 31 | if __name__ == '__main__': 32 | n = int(input().strip()) 33 | 34 | arr = list(map(int, input().rstrip().split())) 35 | 36 | plusMinus(arr) 37 | -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/Simple Array Sum.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'simpleArraySum' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts INTEGER_ARRAY ar as parameter. 14 | # 15 | 16 | def simpleArraySum(ar): 17 | # Write your code here 18 | return sum(ar) 19 | 20 | if __name__ == '__main__': 21 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 22 | 23 | ar_count = int(input().strip()) 24 | 25 | ar = list(map(int, input().rstrip().split())) 26 | 27 | result = simpleArraySum(ar) 28 | 29 | fptr.write(str(result) + '\n') 30 | 31 | fptr.close() 32 | -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/Solve Me First.py: -------------------------------------------------------------------------------- 1 | def solveMeFirst(a,b): 2 | # Hint: Type return a+b below 3 | return a + b 4 | 5 | 6 | num1 = int(input()) 7 | num2 = int(input()) 8 | res = solveMeFirst(num1,num2) 9 | print(res) -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/Staircase.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'staircase' function below. 11 | # 12 | # The function accepts INTEGER n as parameter. 13 | # 14 | 15 | def staircase(n): 16 | # Write your code here 17 | for i in range(0, n): 18 | for j in range(0, n): 19 | if i + j >= n - 1: 20 | print("#",end="") 21 | else: 22 | print(" ",end="") 23 | print("\r") 24 | 25 | if __name__ == '__main__': 26 | n = int(input().strip()) 27 | 28 | staircase(n) 29 | -------------------------------------------------------------------------------- /Algorithms/01 - Warmup/Time Conversion.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'timeConversion' function below. 11 | # 12 | # The function is expected to return a STRING. 13 | # The function accepts STRING s as parameter. 14 | # 15 | 16 | def timeConversion(s): 17 | # Write your code here 18 | if s[-2:] == "AM" and s[:2] == "12": 19 | return "00" + s[2:-2] 20 | elif s[-2:] == "AM": 21 | return s[:-2] 22 | elif s[-2:] == "PM" and s[:2] == "12": 23 | return s[:-2] 24 | else: 25 | return str(int(s[:2]) + 12) + s[2:8] 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | s = input() 31 | 32 | result = timeConversion(s) 33 | 34 | fptr.write(result + '\n') 35 | 36 | fptr.close() 37 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Angry Professor.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'angryProfessor' function below. 11 | # 12 | # The function is expected to return a STRING. 13 | # The function accepts following parameters: 14 | # 1. INTEGER k 15 | # 2. INTEGER_ARRAY a 16 | # 17 | 18 | def angryProfessor(k, a): 19 | # Write your code here 20 | result = len([i for i in a if i <= 0]) 21 | return "NO" if result >= k else "YES" 22 | 23 | if __name__ == '__main__': 24 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 25 | 26 | t = int(input().strip()) 27 | 28 | for t_itr in range(t): 29 | first_multiple_input = input().rstrip().split() 30 | 31 | n = int(first_multiple_input[0]) 32 | 33 | k = int(first_multiple_input[1]) 34 | 35 | a = list(map(int, input().rstrip().split())) 36 | 37 | result = angryProfessor(k, a) 38 | 39 | fptr.write(result + '\n') 40 | 41 | fptr.close() 42 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Beatiful Days at the Movies.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'beautifulDays' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts following parameters: 14 | # 1. INTEGER i 15 | # 2. INTEGER j 16 | # 3. INTEGER k 17 | # 18 | 19 | def beautifulDays(i, j, k): 20 | # Write your code here 21 | s = 0 22 | 23 | for day in range(i, j+1): 24 | if (day - int(str(day)[::-1])) % k == 0: 25 | s += 1 26 | 27 | return s 28 | 29 | if __name__ == '__main__': 30 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 31 | 32 | first_multiple_input = input().rstrip().split() 33 | 34 | i = int(first_multiple_input[0]) 35 | 36 | j = int(first_multiple_input[1]) 37 | 38 | k = int(first_multiple_input[2]) 39 | 40 | result = beautifulDays(i, j, k) 41 | 42 | fptr.write(str(result) + '\n') 43 | 44 | fptr.close() 45 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Beutiful Triplets.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'beautifulTriplets' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts following parameters: 15 | # 1. INTEGER d 16 | # 2. INTEGER_ARRAY arr 17 | # 18 | 19 | def beautifulTriplets(d, arr): 20 | # Write your code here 21 | count = 0 22 | for item in arr: 23 | if item + d in arr and item + 2 * d in arr: 24 | count += 1 25 | return count 26 | 27 | 28 | if __name__ == '__main__': 29 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 30 | 31 | first_multiple_input = input().rstrip().split() 32 | 33 | n = int(first_multiple_input[0]) 34 | 35 | d = int(first_multiple_input[1]) 36 | 37 | arr = list(map(int, input().rstrip().split())) 38 | 39 | result = beautifulTriplets(d, arr) 40 | 41 | fptr.write(str(result) + '\n') 42 | 43 | fptr.close() 44 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Bill Divison.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'bonAppetit' function below. 11 | # 12 | # The function accepts following parameters: 13 | # 1. INTEGER_ARRAY bill 14 | # 2. INTEGER k 15 | # 3. INTEGER b 16 | # 17 | 18 | def bonAppetit(bill, k, b): 19 | # Write your code here 20 | b_actual = (sum(bill) - bill[k]) / 2 21 | b_charged = b 22 | 23 | if b_charged == b_actual: 24 | print("Bon Appetit") 25 | else: 26 | print(int(b_charged - b_actual)) 27 | 28 | if __name__ == '__main__': 29 | first_multiple_input = input().rstrip().split() 30 | 31 | n = int(first_multiple_input[0]) 32 | 33 | k = int(first_multiple_input[1]) 34 | 35 | bill = list(map(int, input().rstrip().split())) 36 | 37 | b = int(input().strip()) 38 | 39 | bonAppetit(bill, k, b) 40 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Cats and a Mouse.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the catAndMouse function below. 10 | def catAndMouse(x, y, z): 11 | if abs(x - z) == abs(y - z): 12 | return "Mouse C" 13 | elif abs(x - z) < abs(y - z): 14 | return "Cat A" 15 | else: 16 | return "Cat B" 17 | 18 | if __name__ == '__main__': 19 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 20 | 21 | q = int(input()) 22 | 23 | for q_itr in range(q): 24 | xyz = input().split() 25 | 26 | x = int(xyz[0]) 27 | 28 | y = int(xyz[1]) 29 | 30 | z = int(xyz[2]) 31 | 32 | result = catAndMouse(x, y, z) 33 | 34 | fptr.write(result + '\n') 35 | 36 | fptr.close() 37 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Cut the Sticks.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'cutTheSticks' function below. 11 | # 12 | # The function is expected to return an INTEGER_ARRAY. 13 | # The function accepts INTEGER_ARRAY arr as parameter. 14 | # 15 | 16 | def cutTheSticks(arr): 17 | # Write your code here 18 | arr.sort(reverse=True) 19 | result = [] 20 | while arr: 21 | result.append(len(arr)) 22 | minimum = arr.pop() 23 | while arr and minimum == arr[-1]: 24 | arr.pop() 25 | return result 26 | 27 | 28 | if __name__ == '__main__': 29 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 30 | 31 | n = int(input().strip()) 32 | 33 | arr = list(map(int, input().rstrip().split())) 34 | 35 | result = cutTheSticks(arr) 36 | 37 | fptr.write('\n'.join(map(str, result))) 38 | fptr.write('\n') 39 | 40 | fptr.close() 41 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Designer PDF Viewer.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | from string import ascii_lowercase 9 | 10 | # 11 | # Complete the 'designerPdfViewer' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts following parameters: 15 | # 1. INTEGER_ARRAY h 16 | # 2. STRING word 17 | # 18 | 19 | def designerPdfViewer(h, word): 20 | # Write your code here 21 | heights = [] 22 | for w in word: 23 | i = ascii_lowercase.find(w) 24 | heights.append(int(h[i])) 25 | return max(heights) * len(word) 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | h = list(map(int, input().rstrip().split())) 31 | 32 | word = input() 33 | 34 | result = designerPdfViewer(h, word) 35 | 36 | fptr.write(str(result) + '\n') 37 | 38 | fptr.close() 39 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Drawing Book.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'pageCount' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts following parameters: 14 | # 1. INTEGER n 15 | # 2. INTEGER p 16 | # 17 | 18 | def pageCount(n, p): 19 | # Write your code here 20 | page_in_book = p // 2 21 | total_pages = n // 2 22 | 23 | from_front = page_in_book 24 | from_back = total_pages - page_in_book 25 | 26 | return min(from_front, from_back) 27 | 28 | if __name__ == '__main__': 29 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 30 | 31 | n = int(input().strip()) 32 | 33 | p = int(input().strip()) 34 | 35 | result = pageCount(n, p) 36 | 37 | fptr.write(str(result) + '\n') 38 | 39 | fptr.close() 40 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Encryption.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'encryption' function below. 12 | # 13 | # The function is expected to return a STRING. 14 | # The function accepts STRING s as parameter. 15 | # 16 | 17 | def encryption(s): 18 | # Write your code here 19 | c = math.ceil(math.sqrt(len(s))) 20 | data = "" 21 | for i in range(c): 22 | data += f"{s[i::c]} " 23 | return data 24 | 25 | 26 | if __name__ == '__main__': 27 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 28 | 29 | s = input() 30 | 31 | result = encryption(s) 32 | 33 | fptr.write(result + '\n') 34 | 35 | fptr.close() 36 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Equalize the Array.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'equalizeArray' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts INTEGER_ARRAY arr as parameter. 15 | # 16 | 17 | def equalizeArray(arr): 18 | # Write your code here 19 | return min(len(arr) - arr.count(i) for i in arr) 20 | 21 | 22 | if __name__ == '__main__': 23 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 24 | 25 | n = int(input().strip()) 26 | 27 | arr = list(map(int, input().rstrip().split())) 28 | 29 | result = equalizeArray(arr) 30 | 31 | fptr.write(str(result) + '\n') 32 | 33 | fptr.close() 34 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Extra Long Factorials.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'extraLongFactorials' function below. 11 | # 12 | # The function accepts INTEGER n as parameter. 13 | # 14 | 15 | def extraLongFactorials(n): 16 | # Write your code here 17 | answer = 1 18 | while n!= 1: 19 | answer *=n 20 | n -=1 21 | print(answer) 22 | 23 | if __name__ == '__main__': 24 | n = int(input().strip()) 25 | 26 | extraLongFactorials(n) 27 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Fair Rations.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'fairRations' function below. 12 | # 13 | # The function is expected to return a STRING. 14 | # The function accepts INTEGER_ARRAY B as parameter. 15 | # 16 | 17 | def fairRations(B): 18 | # Write your code here 19 | num_breads = 0 20 | for i in range(len(B) - 1): 21 | if B[i] % 2 != 0: 22 | B[i] += 1 23 | B[i + 1] += 1 24 | num_breads += 2 25 | 26 | if B[-1] % 2 != 0: 27 | return "NO" 28 | else: 29 | return num_breads 30 | 31 | 32 | if __name__ == '__main__': 33 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 34 | 35 | N = int(input().strip()) 36 | 37 | B = list(map(int, input().rstrip().split())) 38 | 39 | result = fairRations(B) 40 | 41 | fptr.write(str(result) + '\n') 42 | 43 | fptr.close() 44 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Find Digits.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'findDigits' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts INTEGER n as parameter. 14 | # 15 | 16 | def findDigits(n): 17 | # Write your code here 18 | count = 0 19 | for i in list(str(n)): 20 | if int(i) != 0 and n % int(i) == 0: 21 | count += 1 22 | return count 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | 27 | t = int(input().strip()) 28 | 29 | for t_itr in range(t): 30 | n = int(input().strip()) 31 | 32 | result = findDigits(n) 33 | 34 | fptr.write(str(result) + '\n') 35 | 36 | fptr.close() 37 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Jumping on the Clouds - Revisited.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the jumpingOnClouds function below. 10 | def jumpingOnClouds(c, k): 11 | e=100 12 | energy=0 13 | i=0 14 | while(i!=len(c)): 15 | if(c[i]==1): 16 | energy=e-3 17 | e=energy 18 | else: 19 | energy=e-1 20 | e=energy 21 | i+=k 22 | return energy 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | 27 | nk = input().split() 28 | 29 | n = int(nk[0]) 30 | 31 | k = int(nk[1]) 32 | 33 | c = list(map(int, input().rstrip().split())) 34 | 35 | result = jumpingOnClouds(c, k) 36 | 37 | fptr.write(str(result) + '\n') 38 | 39 | fptr.close() -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Migratory Birds.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | from collections import Counter 9 | import operator 10 | 11 | # 12 | # Complete the 'migratoryBirds' function below. 13 | # 14 | # The function is expected to return an INTEGER. 15 | # The function accepts INTEGER_ARRAY arr as parameter. 16 | # 17 | 18 | def migratoryBirds(arr): 19 | # Write your code here 20 | migration_dict = dict(Counter(arr)) 21 | migration_dict = dict(sorted(migration_dict.items())) 22 | maximum_frequency = max(migration_dict, key=migration_dict.get) 23 | return maximum_frequency 24 | 25 | if __name__ == '__main__': 26 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 27 | 28 | arr_count = int(input().strip()) 29 | 30 | arr = list(map(int, input().rstrip().split())) 31 | 32 | result = migratoryBirds(arr) 33 | 34 | fptr.write(str(result) + '\n') 35 | 36 | fptr.close() 37 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Minimum Distances.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'minimumDistances' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts INTEGER_ARRAY a as parameter. 14 | # 15 | 16 | def minimumDistances(a): 17 | # Write your code here 18 | m = len(a) + 1 19 | for i in range(len(a) -1): 20 | for j in range(i + 1, len(a)): 21 | if a[i] == a[j] and m > math.fabs(i - j): 22 | m = math.fabs(i - j) 23 | 24 | if m == len(a) + 1: 25 | return -1 26 | else: 27 | return int(m) 28 | 29 | if __name__ == '__main__': 30 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 31 | 32 | n = int(input().strip()) 33 | 34 | a = list(map(int, input().rstrip().split())) 35 | 36 | result = minimumDistances(a) 37 | 38 | fptr.write(str(result) + '\n') 39 | 40 | fptr.close() 41 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Modified Kaprekar Numbers.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'kaprekarNumbers' function below. 12 | # 13 | # The function accepts following parameters: 14 | # 1. INTEGER p 15 | # 2. INTEGER q 16 | # 17 | 18 | def kaprekarNumbers(p, q): 19 | # Write your code here 20 | results = [] 21 | for i in range(p, q + 1): 22 | square = i ** 2 23 | d = 10 ** len(str(i)) 24 | l = square // d 25 | r = square % d 26 | if l + r == i: 27 | results.append(i) 28 | if results: 29 | print(*results) 30 | else: 31 | print("INVALID RANGE") 32 | 33 | 34 | if __name__ == '__main__': 35 | p = int(input().strip()) 36 | 37 | q = int(input().strip()) 38 | 39 | kaprekarNumbers(p, q) 40 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Sequence Equation.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'permutationEquation' function below. 11 | # 12 | # The function is expected to return an INTEGER_ARRAY. 13 | # The function accepts INTEGER_ARRAY p as parameter. 14 | # 15 | 16 | def permutationEquation(p): 17 | # Write your code here 18 | answer = [] 19 | for i in range(len(p)): 20 | answer.append(str(p.index(p.index(i + 1)+ 1)+ 1)) 21 | return answer 22 | 23 | if __name__ == '__main__': 24 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 25 | 26 | n = int(input().strip()) 27 | 28 | p = list(map(int, input().rstrip().split())) 29 | 30 | result = permutationEquation(p) 31 | 32 | fptr.write('\n'.join(map(str, result))) 33 | fptr.write('\n') 34 | 35 | fptr.close() 36 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Sherlock and Squares.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'squares' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts following parameters: 14 | # 1. INTEGER a 15 | # 2. INTEGER b 16 | # 17 | 18 | def squares(a, b): 19 | # Write your code here 20 | count = math.floor(math.sqrt(b)) - math.floor(math.sqrt(a-1)) 21 | return count 22 | 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | 27 | q = int(input().strip()) 28 | 29 | for q_itr in range(q): 30 | first_multiple_input = input().rstrip().split() 31 | 32 | a = int(first_multiple_input[0]) 33 | 34 | b = int(first_multiple_input[1]) 35 | 36 | result = squares(a, b) 37 | 38 | fptr.write(str(result) + '\n') 39 | 40 | fptr.close() 41 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Strange Counter.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'strangeCounter' function below. 11 | # 12 | # The function is expected to return a LONG_INTEGER. 13 | # The function accepts LONG_INTEGER t as parameter. 14 | # 15 | 16 | def strangeCounter(t): 17 | # Write your code here 18 | phase = 3 19 | while t > phase: 20 | t -= phase 21 | phase *= 2 22 | 23 | return phase - t + 1 24 | 25 | if __name__ == '__main__': 26 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 27 | 28 | t = int(input().strip()) 29 | 30 | result = strangeCounter(t) 31 | 32 | fptr.write(str(result) + '\n') 33 | 34 | fptr.close() 35 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/The Hurdle Race.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'hurdleRace' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts following parameters: 14 | # 1. INTEGER k 15 | # 2. INTEGER_ARRAY height 16 | # 17 | 18 | def hurdleRace(k, height): 19 | # Write your code here 20 | return max(height) - k if max(height) - k > 0 else 0 21 | 22 | if __name__ == '__main__': 23 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 24 | 25 | first_multiple_input = input().rstrip().split() 26 | 27 | n = int(first_multiple_input[0]) 28 | 29 | k = int(first_multiple_input[1]) 30 | 31 | height = list(map(int, input().rstrip().split())) 32 | 33 | result = hurdleRace(k, height) 34 | 35 | fptr.write(str(result) + '\n') 36 | 37 | fptr.close() 38 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Utopian Tree.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'utopianTree' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts INTEGER n as parameter. 14 | # 15 | 16 | def utopianTree(n): 17 | # Write your code here 18 | h = 1 19 | if n < 1: 20 | return h 21 | for i in range(1, n+1): 22 | if i % 2 == 0: 23 | h += 1 24 | else: 25 | h *= 2 26 | return h 27 | 28 | if __name__ == '__main__': 29 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 30 | 31 | t = int(input().strip()) 32 | 33 | for t_itr in range(t): 34 | n = int(input().strip()) 35 | 36 | result = utopianTree(n) 37 | 38 | fptr.write(str(result) + '\n') 39 | 40 | fptr.close() 41 | -------------------------------------------------------------------------------- /Algorithms/02 - Implementation/Viral Advertising.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'viralAdvertising' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts INTEGER n as parameter. 14 | # 15 | 16 | def viralAdvertising(n): 17 | # Write your code here 18 | cumulative = 2 19 | liked = 2 20 | 21 | for i in range(n - 1): 22 | liked = int(3 * liked / 2) 23 | cumulative += liked 24 | 25 | return cumulative 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | n = int(input().strip()) 31 | 32 | result = viralAdvertising(n) 33 | 34 | fptr.write(str(result) + '\n') 35 | 36 | fptr.close() 37 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Beautiful Binary String.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'beautifulBinaryString' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts STRING b as parameter. 14 | # 15 | 16 | 17 | def beautifulBinaryString(b): 18 | # Write your code here 19 | res = 0 20 | 21 | while "010" in b: 22 | res += 1 23 | b = b.replace("010","011", 1) 24 | 25 | return res 26 | 27 | 28 | if __name__ == '__main__': 29 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 30 | 31 | n = int(input().strip()) 32 | 33 | b = input() 34 | 35 | result = beautifulBinaryString(b) 36 | 37 | fptr.write(str(result) + '\n') 38 | 39 | fptr.close() 40 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/CamelCase.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'camelcase' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts STRING s as parameter. 14 | # 15 | 16 | def camelcase(s): 17 | # Write your code here 18 | count = 1 19 | 20 | for letter in s: 21 | if ord(letter) <= ord("Z"): 22 | count += 1 23 | 24 | return count 25 | 26 | if __name__ == '__main__': 27 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 28 | 29 | s = input() 30 | 31 | result = camelcase(s) 32 | 33 | fptr.write(str(result) + '\n') 34 | 35 | fptr.close() 36 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Funny String.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'funnyString' function below. 12 | # 13 | # The function is expected to return a STRING. 14 | # The function accepts STRING s as parameter. 15 | # 16 | 17 | def funnyString(s): 18 | # Write your code here 19 | r = s[::-1] 20 | for i in range(1, len(s)): 21 | if abs(ord(s[i]) - ord(s[i - 1])) != abs(ord(r[i]) - ord(r[i - 1])): return "Not Funny" 22 | return "Funny" 23 | 24 | 25 | if __name__ == '__main__': 26 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 27 | 28 | q = int(input().strip()) 29 | 30 | for q_itr in range(q): 31 | s = input() 32 | 33 | result = funnyString(s) 34 | 35 | fptr.write(result + '\n') 36 | 37 | fptr.close() 38 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Game of Thrones - I.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'gameOfThrones' function below. 12 | # 13 | # The function is expected to return a STRING. 14 | # The function accepts STRING s as parameter. 15 | # 16 | 17 | def gameOfThrones(s): 18 | # Write your code here 19 | string = sorted(s) 20 | current_letter_count = 1 21 | middle = False 22 | for index, char in enumerate(list(string[1:])): 23 | if string[index] != char: 24 | if current_letter_count % 2: 25 | if not middle: 26 | middle = True 27 | else: 28 | return "NO" 29 | current_letter_count += 1 30 | return "YES" 31 | 32 | 33 | if __name__ == '__main__': 34 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 35 | 36 | s = input() 37 | 38 | result = gameOfThrones(s) 39 | 40 | fptr.write(result + '\n') 41 | 42 | fptr.close() 43 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Gemstones.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'gemstones' function below. 11 | # 12 | # The function is expected to return an INTEGER. 13 | # The function accepts STRING_ARRAY arr as parameter. 14 | # 15 | 16 | 17 | def gemstones(arr): 18 | # Write your code here 19 | gems = set(arr[0]) 20 | 21 | for array in arr[1:]: 22 | gems &= set(array) 23 | 24 | return len(gems) 25 | 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | n = int(input().strip()) 31 | 32 | arr = [] 33 | 34 | for _ in range(n): 35 | arr_item = input() 36 | arr.append(arr_item) 37 | 38 | result = gemstones(arr) 39 | 40 | fptr.write(str(result) + '\n') 41 | 42 | fptr.close() 43 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/HackerRank in a String.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'hackerrankInString' function below. 11 | # 12 | # The function is expected to return a STRING. 13 | # The function accepts STRING s as parameter. 14 | # 15 | 16 | 17 | def hackerrankInString(s): 18 | # Write your code here 19 | 20 | pattern = ".*h.*a.*c.*k.*e.*r.*r.*a.*n.*k.*" 21 | 22 | if re.search(pattern, s) is not None: 23 | return "YES" 24 | else: 25 | return "NO" 26 | 27 | 28 | if __name__ == '__main__': 29 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 30 | 31 | q = int(input().strip()) 32 | 33 | for q_itr in range(q): 34 | s = input().strip() 35 | 36 | result = hackerrankInString(s) 37 | 38 | fptr.write(result + '\n') 39 | 40 | fptr.close() 41 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Making Anagrams.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'makingAnagrams' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts following parameters: 15 | # 1. STRING s1 16 | # 2. STRING s2 17 | # 18 | 19 | def makingAnagrams(s1, s2): 20 | # Write your code here 21 | S1 = [0] * 26 22 | for char in s1: 23 | S1[ord(char) - 97] += 1 24 | 25 | S2 = [0] * 26 26 | for char in s2: 27 | S2[ord(char) - 97] += 1 28 | 29 | deletions = 0 30 | for i in range(len(S1)): 31 | deletions += math.fabs(S1[i] - S2[i]) 32 | 33 | return int(deletions) 34 | 35 | 36 | if __name__ == '__main__': 37 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 38 | 39 | s1 = input() 40 | 41 | s2 = input() 42 | 43 | result = makingAnagrams(s1, s2) 44 | 45 | fptr.write(str(result) + '\n') 46 | 47 | fptr.close() 48 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Mars Exploration.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'marsExploration' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts STRING s as parameter. 15 | # 16 | 17 | def marsExploration(s): 18 | # Write your code here 19 | num_errors = 0 20 | 21 | for i, char in enumerate(s): 22 | if i % 3 == 1: 23 | if char != "O": 24 | num_errors += 1 25 | else: 26 | if char != "S": 27 | num_errors += 1 28 | 29 | return num_errors 30 | 31 | 32 | if __name__ == '__main__': 33 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 34 | 35 | s = input().strip() 36 | 37 | result = marsExploration(s) 38 | 39 | fptr.write(str(result) + '\n') 40 | 41 | fptr.close() 42 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Pangrams.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'pangrams' function below. 11 | # 12 | # The function is expected to return a STRING. 13 | # The function accepts STRING s as parameter. 14 | # 15 | 16 | def pangrams(s): 17 | # Write your code here 18 | alpha_set = set(char for char in s.lower() if char.isalpha()) 19 | return "pangram" if len(alpha_set) == 26 else "not pangram" 20 | 21 | 22 | if __name__ == '__main__': 23 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 24 | 25 | s = input() 26 | 27 | result = pangrams(s) 28 | 29 | fptr.write(result + '\n') 30 | 31 | fptr.close() 32 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Seperate the Numbers.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'separateNumbers' function below. 12 | # 13 | # The function accepts STRING s as parameter. 14 | # 15 | 16 | def separateNumbers(s): 17 | # Write your code here 18 | found = False 19 | 20 | for i in range(len(s) // 2): 21 | a = s[:i + 1] 22 | f = n = int(s[:i + 1]) 23 | while len(a) < len(s): 24 | n += 1 25 | a += str(n) 26 | if a == s: 27 | found = True 28 | print("YES", f) 29 | break 30 | if not found: 31 | print("NO") 32 | 33 | 34 | if __name__ == '__main__': 35 | q = int(input().strip()) 36 | 37 | for q_itr in range(q): 38 | s = input() 39 | 40 | separateNumbers(s) 41 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/String Construction.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'stringConstruction' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts STRING s as parameter. 15 | # 16 | 17 | def stringConstruction(s): 18 | # Write your code here 19 | p_set = set() 20 | for i in s: 21 | p_set.add(i) 22 | 23 | return len(p_set) 24 | 25 | 26 | if __name__ == '__main__': 27 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 28 | 29 | q = int(input().strip()) 30 | 31 | for q_itr in range(q): 32 | s = input() 33 | 34 | result = stringConstruction(s) 35 | 36 | fptr.write(str(result) + '\n') 37 | 38 | fptr.close() 39 | -------------------------------------------------------------------------------- /Algorithms/03 - Strings/Super Reduced String.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'superReducedString' function below. 12 | # 13 | # The function is expected to return a STRING. 14 | # The function accepts STRING s as parameter. 15 | # 16 | 17 | def superReducedString(s): 18 | # Write your code here 19 | changed = True 20 | while changed and s != "": 21 | changed = False 22 | for i in range(len(s) - 1): 23 | if s[i] == s[i + 1]: 24 | changed = True 25 | s = s[:i] + s[(i + 2):] 26 | break 27 | if s == "": 28 | return "Empty String" 29 | else: 30 | return s 31 | 32 | 33 | if __name__ == '__main__': 34 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 35 | 36 | s = input() 37 | 38 | result = superReducedString(s) 39 | 40 | fptr.write(result + '\n') 41 | 42 | fptr.close() 43 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Big Sorting.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'bigSorting' function below. 12 | # 13 | # The function is expected to return a STRING_ARRAY. 14 | # The function accepts STRING_ARRAY unsorted as parameter. 15 | # 16 | 17 | def bigSorting(unsorted): 18 | # Write your code here 19 | result = [] 20 | for i in sorted(unsorted, key=lambda i: int(i)): 21 | result.append(i) 22 | return result 23 | 24 | 25 | if __name__ == '__main__': 26 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 27 | 28 | n = int(input().strip()) 29 | 30 | unsorted = [] 31 | 32 | for _ in range(n): 33 | unsorted_item = input() 34 | unsorted.append(unsorted_item) 35 | 36 | result = bigSorting(unsorted) 37 | 38 | fptr.write('\n'.join(result)) 39 | fptr.write('\n') 40 | 41 | fptr.close() 42 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Correctness and the Loop Invariant.py: -------------------------------------------------------------------------------- 1 | def insertion_sort(l): 2 | for i in range(1, len(l)): 3 | j = i 4 | key = l[i] 5 | while (j > 0) and (l[j - 1] > key): 6 | l[j] = l[j - 1] 7 | j -= 1 8 | l[j] = key 9 | return l 10 | 11 | 12 | m = int(input().strip()) 13 | ar = [int(i) for i in input().strip().split()] 14 | insertion_sort(ar) 15 | print(" ".join(map(str, ar))) 16 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Counting Sort 1.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'countingSort' function below. 8 | # 9 | # The function is expected to return an INTEGER_ARRAY. 10 | # The function accepts INTEGER_ARRAY arr as parameter. 11 | # 12 | 13 | 14 | def countingSort(arr): 15 | # Write your code here 16 | total = [0] * 100 17 | for j in range(0, len(arr)): 18 | temp = arr[j] 19 | total[temp] += 1 20 | return total 21 | 22 | 23 | if __name__ == '__main__': 24 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 25 | 26 | n = int(input().strip()) 27 | 28 | arr = list(map(int, input().rstrip().split())) 29 | 30 | result = countingSort(arr) 31 | 32 | fptr.write(' '.join(map(str, result))) 33 | fptr.write('\n') 34 | 35 | fptr.close() 36 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Counting Sort 2.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'countingSort' function below. 8 | # 9 | # The function is expected to return an INTEGER_ARRAY. 10 | # The function accepts INTEGER_ARRAY arr as parameter. 11 | # 12 | 13 | 14 | def countingSort(arr): 15 | # Write your code here 16 | answer = [] 17 | count = [0] * 100 18 | for item in arr: 19 | count[item] += 1 20 | 21 | for i in range(100): 22 | if count[i] > 0: 23 | answer.extend([str(i)] * count[i]) 24 | return answer 25 | 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | n = int(input().strip()) 31 | 32 | arr = list(map(int, input().rstrip().split())) 33 | 34 | result = countingSort(arr) 35 | 36 | fptr.write(' '.join(map(str, result))) 37 | fptr.write('\n') 38 | 39 | fptr.close() 40 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Find the Median.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'findMedian' function below. 8 | # 9 | # The function is expected to return an INTEGER. 10 | # The function accepts INTEGER_ARRAY arr as parameter. 11 | # 12 | 13 | 14 | def findMedian(arr): 15 | # Write your code here 16 | arr.sort() 17 | return arr[len(arr) // 2] 18 | 19 | 20 | if __name__ == '__main__': 21 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 22 | 23 | n = int(input().strip()) 24 | 25 | arr = list(map(int, input().rstrip().split())) 26 | 27 | result = findMedian(arr) 28 | 29 | fptr.write(str(result) + '\n') 30 | 31 | fptr.close() 32 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Insertion Sort - Part 1.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'insertionSort1' function below. 12 | # 13 | # The function accepts following parameters: 14 | # 1. INTEGER n 15 | # 2. INTEGER_ARRAY arr 16 | # 17 | 18 | 19 | def insertionSort1(n, arr): 20 | # Write your code here 21 | target = arr[n - 1] 22 | index = n - 2 23 | 24 | while (target < arr[index]) and (index >= 0): 25 | arr[index + 1] = arr[index] 26 | print(*arr) 27 | index -= 1 28 | 29 | arr[index + 1] = target 30 | print(*arr) 31 | 32 | 33 | if __name__ == '__main__': 34 | n = int(input().strip()) 35 | 36 | arr = list(map(int, input().rstrip().split())) 37 | 38 | insertionSort1(n, arr) 39 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Insertion Sort - Part 2.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | 4 | # 5 | # Complete the 'insertionSort2' function below. 6 | # 7 | # The function accepts following parameters: 8 | # 1. INTEGER n 9 | # 2. INTEGER_ARRAY arr 10 | # 11 | 12 | def insertionSort2(n, arr): 13 | # Write your code here 14 | i = 1 15 | switch = False 16 | while i < len(arr): 17 | j = i 18 | switch = False 19 | while arr[j] < arr[j - 1] and j > 0: 20 | arr[j], arr[j - 1] = arr[j - 1], arr[j] 21 | switch = True 22 | j -= 1 23 | i += 1 24 | for num in arr: 25 | print(num, "", end="") 26 | if arr.index(num) == len(arr) - 1: 27 | print() 28 | 29 | 30 | if __name__ == '__main__': 31 | n = int(input().strip()) 32 | 33 | arr = list(map(int, input().rstrip().split())) 34 | 35 | insertionSort2(n, arr) 36 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Insertion Sort Advanced Analysis.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | import array 3 | import bisect 4 | import os 5 | 6 | 7 | # 8 | # Complete the 'insertionSort' function below. 9 | # 10 | # The function is expected to return an INTEGER. 11 | # The function accepts INTEGER_ARRAY arr as parameter. 12 | # 13 | 14 | 15 | def insertionSort(arr): 16 | # Write your code here 17 | result = 0 18 | sarr = array.array("I", [arr[0]]) 19 | for i in range(1, len(arr)): 20 | e = arr[i] 21 | j = bisect.bisect_right(sarr, e) 22 | sarr.insert(j, e) 23 | result += i - j 24 | return result 25 | 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | t = int(input().strip()) 31 | 32 | for t_itr in range(t): 33 | n = int(input().strip()) 34 | 35 | arr = list(map(int, input().rstrip().split())) 36 | 37 | result = insertionSort(arr) 38 | 39 | fptr.write(str(result) + '\n') 40 | 41 | fptr.close() 42 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Intro to Tutorial Challenges.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'introTutorial' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts following parameters: 15 | # 1. INTEGER V 16 | # 2. INTEGER_ARRAY arr 17 | # 18 | 19 | def introTutorial(V, arr): 20 | # Write your code here 21 | return arr.index(V) 22 | 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | 27 | V = int(input().strip()) 28 | 29 | n = int(input().strip()) 30 | 31 | arr = list(map(int, input().rstrip().split())) 32 | 33 | result = introTutorial(V, arr) 34 | 35 | fptr.write(str(result) + '\n') 36 | 37 | fptr.close() 38 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/Quicksort 1 - Partition.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'quickSort' function below. 8 | # 9 | # The function is expected to return an INTEGER_ARRAY. 10 | # The function accepts INTEGER_ARRAY arr as parameter. 11 | # 12 | 13 | def quickSort(arr): 14 | # Write your code here 15 | pivot = arr[0] 16 | left = [] 17 | right = [] 18 | for element in arr: 19 | if element < pivot: 20 | left.append(element) 21 | else: 22 | right.append(element) 23 | return left + right 24 | 25 | 26 | if __name__ == '__main__': 27 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 28 | 29 | n = int(input().strip()) 30 | 31 | arr = list(map(int, input().rstrip().split())) 32 | 33 | result = quickSort(arr) 34 | 35 | fptr.write(' '.join(map(str, result))) 36 | fptr.write('\n') 37 | 38 | fptr.close() 39 | -------------------------------------------------------------------------------- /Algorithms/04 - Sorting/The Full Counting Sort.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | import collections 3 | 4 | 5 | # 6 | # Complete the 'countSort' function below. 7 | # 8 | # The function accepts 2D_STRING_ARRAY arr as parameter. 9 | # 10 | 11 | def countSort(arr): 12 | # Write your code here 13 | default_dict = collections.defaultdict(list) 14 | for i in range(len(arr)): 15 | key, value = arr[i].split() 16 | if i < n // 2: 17 | default_dict[int(key)].append("-") 18 | else: 19 | default_dict[int(key)].append(value) 20 | ordered_dict = collections.OrderedDict(sorted(default_dict.items())) 21 | print(" ".join([" ".join(l) for l in ordered_dict.values()])) 22 | 23 | 24 | if __name__ == '__main__': 25 | n = int(input().strip()) 26 | 27 | arr = [] 28 | 29 | for _ in range(n): 30 | arr.append(input().rstrip()) 31 | 32 | countSort(arr) 33 | -------------------------------------------------------------------------------- /Algorithms/05 - Search/Short Palindrome.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'shortPalindrome' function below. 8 | # 9 | # The function is expected to return an INTEGER. 10 | # The function accepts STRING s as parameter. 11 | # 12 | 13 | def shortPalindrome(s): 14 | # Write your code here 15 | mod = 10 ** 9 + 7 16 | c1 = [0] * 26 17 | c2 = [0] * 26 * 26 18 | c3 = [0] * 26 * 26 19 | count = 0 20 | r26 = list(range(26)) 21 | for c in s: 22 | k = ord(c) - 97 23 | p = 26 * k - 1 24 | q = k - 26 25 | for i in r26: 26 | q += 26 27 | p += 1 28 | count += c3[q] 29 | c3[p] += c2[p] 30 | c2[p] += c1[i] 31 | c1[k] += 1 32 | 33 | return count % mod 34 | 35 | 36 | if __name__ == '__main__': 37 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 38 | 39 | s = input() 40 | 41 | result = shortPalindrome(s) 42 | 43 | fptr.write(str(result) + '\n') 44 | 45 | fptr.close() 46 | -------------------------------------------------------------------------------- /Artificial Intelligence/01 - Bot Building/Battleship 1 Player.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Artificial Intelligence/01 - Bot Building/Battleship 1 Player.py -------------------------------------------------------------------------------- /Artificial Intelligence/01 - Bot Building/Bot saves Princes - 2.py: -------------------------------------------------------------------------------- 1 | def nextMove(n, row, column, grid): 2 | princess_row = 0 3 | princess_column = 0 4 | for i in range(n): 5 | for j in range(n): 6 | if grid[i][j] == "p": 7 | princess_row = i 8 | princess_column = j 9 | 10 | if row < princess_row: 11 | return "DOWN" 12 | if row > princess_row: 13 | return "UP" 14 | if column < princess_column: 15 | return "RIGHT" 16 | if column > princess_column: 17 | return "LEFT" 18 | return "" 19 | 20 | 21 | n = int(input()) # length of grid 22 | r, c = [int(i) for i in input().strip().split()] # bot location 23 | grid = [] 24 | for i in range(0, n): 25 | grid.append(input()) 26 | 27 | print(nextMove(n, r, c, grid)) 28 | -------------------------------------------------------------------------------- /Artificial Intelligence/01 - Bot Building/BotClean Stochastic.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | def nextMove(posr, posc, board): 4 | if board[posr][posc] == "d": 5 | print("CLEAN") 6 | return 7 | 8 | for i in range(5): 9 | for j in range(5): 10 | if board[i][j] == "d": 11 | row = i 12 | column = j 13 | 14 | if posr > row: 15 | print("UP") 16 | return 17 | if posr < row: 18 | print("DOWN") 19 | return 20 | if posc > column: 21 | print("LEFT") 22 | return 23 | if posc < column: 24 | print("RIGHT") 25 | return 26 | 27 | print("") 28 | 29 | 30 | if __name__ == "__main__": 31 | pos = [int(i) for i in input().strip().split()] 32 | board = [[j for j in input().strip()] for i in range(5)] 33 | nextMove(pos[0], pos[1], board) 34 | -------------------------------------------------------------------------------- /Artificial Intelligence/01 - Bot Building/test.txt: -------------------------------------------------------------------------------- 1 | RIGHT 2 | b-ooo 3 | -dooo 4 | ooooo 5 | ooooo 6 | ooooo 7 | -------------------------------------------------------------------------------- /Badges/10_days_of_statistics_5_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/10_days_of_statistics_5_star.png -------------------------------------------------------------------------------- /Badges/30-days-of-code_5_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/30-days-of-code_5_star.png -------------------------------------------------------------------------------- /Badges/SQL_adv_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/SQL_adv_badge.png -------------------------------------------------------------------------------- /Badges/c#_basic_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/c#_basic_skill.png -------------------------------------------------------------------------------- /Badges/java_5_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/java_5_star.png -------------------------------------------------------------------------------- /Badges/java_basic_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/java_basic_skill.png -------------------------------------------------------------------------------- /Badges/problem-solving_stars_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/problem-solving_stars_5.png -------------------------------------------------------------------------------- /Badges/problem-solving_stars_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/problem-solving_stars_6.png -------------------------------------------------------------------------------- /Badges/problem_solving_basic_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/problem_solving_basic_skill.png -------------------------------------------------------------------------------- /Badges/problem_solving_intermediate_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/problem_solving_intermediate_skill.png -------------------------------------------------------------------------------- /Badges/python_5_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/python_5_star.png -------------------------------------------------------------------------------- /Badges/python_basic_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/python_basic_skill.png -------------------------------------------------------------------------------- /Badges/r_int_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/r_int_badge.png -------------------------------------------------------------------------------- /Badges/se_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/se_badge.png -------------------------------------------------------------------------------- /Badges/se_intern_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/se_intern_badge.png -------------------------------------------------------------------------------- /Badges/sql_5_star.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/sql_5_star.png -------------------------------------------------------------------------------- /Badges/sql_basic_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/sql_basic_skill.png -------------------------------------------------------------------------------- /Badges/sql_intermediate_skill.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Badges/sql_intermediate_skill.png -------------------------------------------------------------------------------- /C++/01 - Introduction/Input and Output.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | using namespace std; 7 | 8 | 9 | int main() { 10 | /* Enter your code here. Read input from STDIN. Print output to STDOUT */ 11 | int a,b,c,d; 12 | cin >>a >>b >>c; 13 | d = a + b + c; 14 | cout << d; 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Data Structures/01 - Arrays/Arrays - DS.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'reverseArray' function below. 8 | # 9 | # The function is expected to return an INTEGER_ARRAY. 10 | # The function accepts INTEGER_ARRAY a as parameter. 11 | # 12 | 13 | 14 | def reverseArray(arr): 15 | # Write your code here 16 | return arr[::-1] 17 | 18 | 19 | if __name__ == '__main__': 20 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 21 | 22 | arr_count = int(input().strip()) 23 | 24 | arr = list(map(int, input().rstrip().split())) 25 | 26 | res = reverseArray(arr) 27 | 28 | fptr.write(' '.join(map(str, res))) 29 | fptr.write('\n') 30 | 31 | fptr.close() 32 | -------------------------------------------------------------------------------- /Java/1 - Introduction/If Else/Solution.java: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Author: Eda AYDIN 4 | */ 5 | 6 | import java.util.*; 7 | 8 | public class Solution { 9 | 10 | public static void main(String[] args) { 11 | try (/* Enter your code here. Read input from STDIN. 12 | Print output to STDOUT. Your class should be named Solution. */ 13 | Scanner scan = new Scanner(System.in)) { 14 | int n = scan.nextInt(); 15 | 16 | if (n % 2 != 0) { 17 | System.out.println("Weird"); 18 | } 19 | else { 20 | if (n>= 2 && n <= 5){ 21 | System.out.println("Not Weird");} 22 | else if (n>= 6 && n <= 20){ 23 | System.out.println("Weird");} 24 | else { 25 | System.out.println("Not Weird");} 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Java/1 - Introduction/Java End of File/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | public class Solution { 4 | 5 | public static void main(String[] args) { 6 | /* Enter your code here. Read input from STDIN. 7 | Print output to STDOUT. Your class should be named Solution. */ 8 | Scanner input = new Scanner(System.in); 9 | String line; 10 | int i = 1; 11 | while(input.hasNext()) 12 | { 13 | line = input.nextLine(); 14 | System.out.println(i + " "+ line); 15 | i++; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Java/1 - Introduction/Java Int to String/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | /* Enter your code here. Read input from STDIN. 8 | Print output to STDOUT. Your class should be named Solution. */ 9 | Scanner input = new Scanner(System.in); 10 | int n = input.nextInt(); 11 | String s = String.valueOf(n); 12 | 13 | if (n == Integer.parseInt(s)) { 14 | System.out.println("Good job"); 15 | } else { 16 | System.out.println("Wrong answer."); 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Java/1 - Introduction/Java Loop I/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | 3 | import static java.util.stream.Collectors.joining; 4 | 5 | 6 | public class Solution { 7 | public static void main(String[] args) throws IOException { 8 | BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); 9 | 10 | int N = Integer.parseInt(bufferedReader.readLine().trim()); 11 | for(int i = 1; i <= 10; i++){ 12 | System.out.println(N + " x " + i + " = " + N*i); 13 | } 14 | bufferedReader.close(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Java/1 - Introduction/Java Loops II/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.*; 2 | 3 | class Solution { 4 | public static void main(String []argh){ 5 | Scanner in = new Scanner(System.in); 6 | int t=in.nextInt(); 7 | for(int i=0;i 0 && h > 0; 13 | 14 | if (!flag) 15 | { 16 | System.out.println("java.lang.Exception: Breadth and height must be positive"); 17 | } 18 | else 19 | { 20 | System.out.println(b*h); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /Java/1 - Introduction/Java Stdin and Stdout I/Solution.java: -------------------------------------------------------------------------------- 1 | /* 2 | Java Stdin and Stdout I 3 | 4 | Scanner scanner = new Scanner(System.in); 5 | String myString = scanner.next(); 6 | int myInt = scanner.nextInt(); 7 | scanner.close(); 8 | 9 | System.out.println("myString is: " + myString); 10 | System.out.println("myInt is: " + myInt); 11 | 12 | Author: Eda AYDIN 13 | */ 14 | 15 | import java.util.*; 16 | 17 | public class Solution { 18 | 19 | public static void main(String[] args) { 20 | try (Scanner scan = new Scanner(System.in)) { 21 | int a = scan.nextInt(); 22 | int b = scan.nextInt(); 23 | int c = scan.nextInt(); 24 | 25 | System.out.println(a); 26 | System.out.println(b); 27 | System.out.println(c); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Java/1 - Introduction/Java Stdin and Stdout II/Solution.java: -------------------------------------------------------------------------------- 1 | /* 2 | Sample Input 3 | 4 | 42 5 | 3.1415 6 | Welcome to HackerRank's Java tutorials! 7 | Sample Output 8 | 9 | String: Welcome to HackerRank's Java tutorials! 10 | Double: 3.1415 11 | Int: 42 12 | 13 | Author: Eda AYDIN 14 | */ 15 | 16 | import java.util.*; 17 | 18 | public class Solution { 19 | 20 | public static void main(String[] args) { 21 | /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ 22 | Scanner scan = new Scanner(System.in); 23 | int i = scan.nextInt(); 24 | double d = scan.nextDouble(); 25 | scan.nextLine(); 26 | String s = scan.nextLine(); 27 | scan.close(); 28 | 29 | System.out.println("String: " + s); 30 | System.out.println("Double: " + d); 31 | System.out.println("Int: " + i); 32 | } 33 | } -------------------------------------------------------------------------------- /Java/2 - String/Java Regex/Solution.java: -------------------------------------------------------------------------------- 1 | import org.apache.commons.validator.routines.InetAddressValidator; 2 | import java.util.Scanner; 3 | 4 | class Solution{ 5 | 6 | public static void main(String[] args){ 7 | Scanner in = new Scanner(System.in); 8 | while(in.hasNext()){ 9 | String IP = in.next(); 10 | System.out.println(IP.matches(new MyRegex().pattern)); 11 | } 12 | 13 | } 14 | } 15 | 16 | //Write your code here 17 | class MyRegex{ 18 | String IPV4_REGEX = "^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + 19 | "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + 20 | "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\." + 21 | "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"; 22 | 23 | public String pattern = IPV4_REGEX; 24 | } -------------------------------------------------------------------------------- /Java/2 - String/Java String Reverse/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc=new Scanner(System.in); 9 | String A=sc.next(); 10 | /* Enter your code here. Print output to STDOUT. */ 11 | 12 | StringBuilder reverseA = new StringBuilder(); 13 | reverseA.append(A); 14 | reverseA.reverse(); 15 | 16 | System.out.println(A.contentEquals(reverseA)?"Yes":"No"); 17 | } 18 | } 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Java/2 - String/Java String Tokens/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | Scanner scan = new Scanner(System.in); 8 | String s = scan.nextLine(); 9 | scan.close(); 10 | 11 | s = s.trim(); 12 | if (s.length() == 0) { 13 | System.out.println(0); 14 | } else { 15 | String[] strings = s.split("[!,?._'@ ]+"); 16 | System.out.println(strings.length); 17 | for(int i = 0; i < strings.length; i++){ 18 | System.out.println(strings[i]); 19 | } 20 | } 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /Java/2 - String/Java Strings Introduction/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | 4 | public class Solution { 5 | 6 | public static void main(String[] args) { 7 | 8 | Scanner sc=new Scanner(System.in); 9 | String A=sc.next(); 10 | String B=sc.next(); 11 | /* Enter your code here. Print output to STDOUT. */ 12 | 13 | System.out.println(A.length() + B.length()); 14 | System.out.println(A.compareTo(B)>0?"Yes":"No"); 15 | String capitalizefl_A = A.substring(0,1).toUpperCase() + A.substring(1); 16 | String capitalizefl_B = B.substring(0,1).toUpperCase() + B.substring(1); 17 | System.out.println(capitalizefl_A + " "+ capitalizefl_B); 18 | 19 | 20 | } 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Java/2 - String/Java Substring/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner in = new Scanner(System.in); 11 | String S = in.next(); 12 | int start = in.nextInt(); 13 | int end = in.nextInt(); 14 | System.out.println(S.substring(start, end)); 15 | } 16 | } -------------------------------------------------------------------------------- /Java/2 - String/Pattern Syntax Checker/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | import java.util.regex.*; 3 | 4 | public class Solution 5 | { 6 | public static void main(String[] args){ 7 | Scanner in = new Scanner(System.in); 8 | int testCases = Integer.parseInt(in.nextLine()); 9 | while(testCases>0){ 10 | String pattern = in.nextLine(); 11 | //Write your code 12 | try { 13 | Pattern.compile(pattern); 14 | System.out.println("Valid"); 15 | } catch(PatternSyntaxException e) { 16 | System.out.println("Invalid"); 17 | } 18 | testCases--; 19 | } 20 | } 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Java/2 - String/Tag Content Extractor/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution{ 8 | public static void main(String[] args){ 9 | 10 | Scanner in = new Scanner(System.in); 11 | int testCases = Integer.parseInt(in.nextLine()); 12 | Pattern pattern = Pattern.compile("<([^>]+)>([^<]+)"); 13 | while(testCases>0){ 14 | String line = in.nextLine(); 15 | 16 | //Write your code here 17 | Matcher matcher = pattern.matcher(line); 18 | int matches = 0; 19 | while(matcher.find()){ 20 | matches ++; 21 | System.out.println(matcher.group(2)); 22 | } 23 | if(matches == 0){ 24 | System.out.println("None"); 25 | } 26 | 27 | testCases--; 28 | } 29 | } 30 | } 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Java/2 - String/Valid Username Regular Expression/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | class UsernameValidator { 3 | /* 4 | * Write regular expression here. 5 | */ 6 | public static final String regularExpression = 7 | "#[a-zA-Z][a-zA-Z0-9_]{7,29}$"; 8 | } 9 | 10 | 11 | public class Solution { 12 | private static final Scanner scan = new Scanner(System.in); 13 | 14 | public static void main(String[] args) { 15 | int n = Integer.parseInt(scan.nextLine()); 16 | while (n-- != 0) { 17 | String userName = scan.nextLine(); 18 | 19 | if (userName.matches(UsernameValidator.regularExpression)) { 20 | System.out.println("Valid"); 21 | } else { 22 | System.out.println("Invalid"); 23 | } 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Java/3 - BigNumber/Java BigDecimal/Solution.java: -------------------------------------------------------------------------------- 1 | import java.math.BigDecimal; 2 | import java.util.*; 3 | class Solution{ 4 | public static void main(String []args){ 5 | //Input 6 | Scanner sc= new Scanner(System.in); 7 | int n=sc.nextInt(); 8 | String []s=new String[n+2]; 9 | for(int i=0;i=1; j--){ 17 | if(new BigDecimal(s[j]).compareTo(new BigDecimal(s[j-1]))>0){ 18 | String temp = s[j]; 19 | s[j] = s[j-1]; 20 | s[j-1] = temp; 21 | } 22 | else { 23 | break; 24 | } 25 | } 26 | } 27 | 28 | //Output 29 | for(int i=0;i deque = new ArrayDeque<>(); 6 | HashSet set = new HashSet<>(); 7 | int n = in.nextInt(); 8 | int m = in.nextInt(); 9 | int max = Integer.MIN_VALUE; 10 | 11 | for (int i = 0; i < n; i++) { 12 | int num = in.nextInt(); 13 | 14 | deque.add(num); 15 | set.add(num); 16 | 17 | if(deque.size() == m){ 18 | if (set.size() > max) 19 | max = set.size(); 20 | int first = (int) deque.remove(); 21 | if (!deque.contains(first)) 22 | set.remove(first); 23 | } 24 | } 25 | System.out.println(max); 26 | } 27 | } 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Java/4 - Data Structures/Java Hashset/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) { 10 | Scanner s = new Scanner(System.in); 11 | int t = s.nextInt(); 12 | String [] pair_left = new String[t]; 13 | String [] pair_right = new String[t]; 14 | 15 | for (int i = 0; i < t; i++) { 16 | pair_left[i] = s.next(); 17 | pair_right[i] = s.next(); 18 | } 19 | 20 | //Write your code here 21 | HashSet pairs = new HashSet(t); 22 | 23 | for(int i = 0; i name_phone = new HashMap<>(); 10 | Scanner in = new Scanner(System.in); 11 | int n=in.nextInt(); 12 | in.nextLine(); 13 | for(int i=0;i 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Java/7 - Advanced/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Java/7 - Advanced/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Java/7 - Advanced/Java MD5/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.security.MessageDigest; 4 | import java.util.Scanner; 5 | 6 | public class Solution { 7 | 8 | public static void main(String[] args) { 9 | /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ 10 | Scanner scanner = new Scanner(System.in); 11 | String str = scanner.next(); 12 | scanner.close(); 13 | try { 14 | MessageDigest md = MessageDigest.getInstance("MD5"); 15 | md.update(str.getBytes()); 16 | byte[] digest = md.digest(); 17 | for (byte b : digest) 18 | { 19 | System.out.printf("%02x",b); 20 | } 21 | } 22 | catch (Exception ex) 23 | { 24 | throw new RuntimeException(ex); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Java/7 - Advanced/Java Reflection - Attributes/Solution.java: -------------------------------------------------------------------------------- 1 | public class Solution { 2 | 3 | public static void main(String[] args){ 4 | Class student = Student.class; 5 | Method[] methods = student.getDeclaredMethods(); 6 | 7 | ArrayList methodList = new ArrayList<>(); 8 | for(Method method : methods){ 9 | methodList.add(method.getName()); 10 | } 11 | Collections.sort(methodList); 12 | for(String name: methodList){ 13 | System.out.println(name); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /Java/7 - Advanced/Java SHA - 256/Solution.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.nio.charset.StandardCharsets; 3 | import java.security.MessageDigest; 4 | import java.security.NoSuchAlgorithmException; 5 | import java.util.*; 6 | 7 | public class Solution { 8 | 9 | public static void main(String[] args) throws NoSuchAlgorithmException { 10 | /* Enter your code here. Read input from STDIN. 11 | Print output to STDOUT. Your class should be named Solution. */ 12 | 13 | Scanner scanner = new Scanner(System.in); 14 | MessageDigest messageDigest = MessageDigest.getInstance("SHA-256"); 15 | messageDigest.reset(); 16 | messageDigest.update(scanner.nextLine().getBytes(StandardCharsets.UTF_8)); 17 | for (byte i : messageDigest.digest()) 18 | { 19 | System.out.printf("%02x",i); 20 | } 21 | System.out.println(); 22 | } 23 | } -------------------------------------------------------------------------------- /Java/7 - Advanced/Java Singleton Pattern/Singleton.java: -------------------------------------------------------------------------------- 1 | import java.io.*; 2 | import java.util.*; 3 | import java.text.*; 4 | import java.math.*; 5 | import java.util.regex.*; 6 | import java.lang.reflect.*; 7 | 8 | 9 | class Singleton { 10 | private Singleton() {} 11 | public String str; 12 | private static Singleton instance = null; 13 | public static Singleton getSingleInstance() { 14 | if (instance == null) { 15 | instance = new Singleton(); 16 | } 17 | return instance; 18 | } 19 | } -------------------------------------------------------------------------------- /ProjectEuler/01-Multiplesof3and5.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | # If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below N. 4 | 5 | import sys 6 | 7 | t = int(input().strip()) 8 | for a0 in range(t): 9 | n = int(input().strip()) 10 | n = n - 1 11 | n3 = n // 3 12 | n5 = n // 5 13 | n15 = n // 15 14 | sum3 = 3 * n3 * (n3 + 1) // 2 15 | sum5 = 5 * n5 * (n5 + 1) // 2 16 | sum15 = 15 * n15 * (n15 + 1) // 2 17 | print(sum3 + sum5 - sum15) 18 | -------------------------------------------------------------------------------- /ProjectEuler/03-LargestPrimeFactor.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | 5 | def p_factor(n): 6 | if n in [1, 2, 3]: 7 | return True 8 | if n % 2==0: 9 | return n//2 10 | else: 11 | for i in range(3, int(n**0.5)+1, 2): 12 | if n % i == 0: 13 | return n//i 14 | return True 15 | 16 | t = int(input().strip()) 17 | for a0 in range(t): 18 | n = int(input().strip()) 19 | while True: 20 | prime = p_factor(n) 21 | if prime is True: 22 | print(n) 23 | break 24 | else: 25 | n = prime -------------------------------------------------------------------------------- /ProjectEuler/13-LargeSum.py: -------------------------------------------------------------------------------- 1 | # Work out the first ten digits of the sum of N 50-digit numbers. 2 | 3 | # Input Format 4 | # First line contains N, next N lines contain a 50 digit number each. 5 | 6 | # Constraints 7 | # 1 <= N <= 10^3 8 | 9 | # Output Format 10 | # Print only first 10 digit of the final sum 11 | 12 | print(str(sum([int(input()) for _ in range(int(input()))]))[:10]) -------------------------------------------------------------------------------- /ProjectEuler/15-LatticePaths.py: -------------------------------------------------------------------------------- 1 | #Starting in the top left corner of 2x2 grid, and only being able to move to the right and down, there are eaxctly 6 routes to the bottom right corner. 2 | 3 | #How many such routes are there through a NXM grid? 4 | # As number of ways can be very large, print it module (10^9 + 7) 5 | 6 | # Input Format 7 | # The first line contains an integer T, the number of testcases. 8 | # T lines follow, each containing an integer N and M. 9 | 10 | # Constraints 11 | # 1 <= T <= 10^3 12 | # 1 <= N <= 500 13 | # 1 <= M <= 500 14 | 15 | # Output Format 16 | # Output T lines, one for each testcase, the required answer. 17 | 18 | # Sample Input 19 | # 2 20 | # 2 2 21 | # 3 2 22 | 23 | # Sample Output 24 | # 6 25 | # 10 26 | from math import factorial as fac 27 | 28 | for _ in range(int(input())): 29 | n, m = list(map(int, input().strip().split())) 30 | print(int(((fac(n+m)//fac(n))//(fac(m)))%((10**9) + 7))) -------------------------------------------------------------------------------- /ProjectEuler/16-PowerDigitSum.py: -------------------------------------------------------------------------------- 1 | # 2^9 = 512 and the sum of its digits is 5 + 1 + 2 = 8 2 | # What is the sum of the digits of the number 2^N? 3 | 4 | # Input Format 5 | # The first line contains an integer T, i.e., number of test cases. 6 | # Next T lines will contain an integer N. 7 | 8 | # Constraints 9 | # 1 <= T <= 100 10 | # 1 <= N <= 10^4 11 | 12 | # Output Format 13 | # Print the values corresponding to each test case. 14 | 15 | # Sample Input 16 | # 3 17 | # 3 18 | # 4 19 | # 7 20 | 21 | # Sample Output 22 | # 8 23 | # 7 24 | # 11 25 | 26 | print(*[(lambda n: sum([int(i) for i in str(2**n)]))(int(input())) for _ in range(int(input()))], sep='\n') -------------------------------------------------------------------------------- /Python/01 - Introduction/Arithmetic Operators.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | a = int(input()) 3 | b = int(input()) 4 | 5 | print(a + b) 6 | print(a - b) 7 | print(a * b) -------------------------------------------------------------------------------- /Python/01 - Introduction/Loops.py: -------------------------------------------------------------------------------- 1 | if __name__ == "__main": 2 | n = int(input()) 3 | 4 | for i in range(n): 5 | print(i ** 2) 6 | -------------------------------------------------------------------------------- /Python/01 - Introduction/Print a function.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function 2 | 3 | if __name__ == '__main__': 4 | n = int(input()) 5 | 6 | for i in range(1, n + 1): 7 | print(i, end="") 8 | -------------------------------------------------------------------------------- /Python/01 - Introduction/Python - Divison.py: -------------------------------------------------------------------------------- 1 | from __future__ import division 2 | 3 | if __name__ == '__main__': 4 | a = int(input()) 5 | b = int(input()) 6 | 7 | print (a//b) 8 | print (a/b) -------------------------------------------------------------------------------- /Python/01 - Introduction/Python If-Else.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | 11 | if __name__ == '__main__': 12 | n = int(input().strip()) 13 | 14 | if n % 2 == 1 or 6 <= n <= 20: 15 | print('Weird') 16 | else: 17 | print('Not Weird') 18 | -------------------------------------------------------------------------------- /Python/01 - Introduction/Write a function.py: -------------------------------------------------------------------------------- 1 | def is_leap(year): 2 | leap = False 3 | 4 | # Write your logic here 5 | if year % 400 == 0: 6 | leap = True 7 | elif year % 4 == 0 and year % 100 != 0: 8 | leap = True 9 | return leap 10 | 11 | 12 | year = int(input()) 13 | print(is_leap(year)) 14 | -------------------------------------------------------------------------------- /Python/02 - Basic Data Types/Find the Maximum Depth.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | arr = list(set(map(int, input().split()))) 4 | 5 | arr.sort() 6 | print(arr[-2]) -------------------------------------------------------------------------------- /Python/02 - Basic Data Types/Finding the percentage.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | student_marks = {} 4 | for _ in range(n): 5 | line = input().split() 6 | student_marks[line[0]] = list(map(float, line[1:])) 7 | print('%.2f'.format(sum(student_marks[input()]) / 3)) 8 | -------------------------------------------------------------------------------- /Python/02 - Basic Data Types/List Comprehesion.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | x = int(input()) 3 | y = int(input()) 4 | z = int(input()) 5 | n = int(input()) 6 | 7 | output= [] 8 | xyx = [] 9 | 10 | for X in range(x+1): 11 | for Y in range(y+1): 12 | for Z in range(z + 1): 13 | if X+Y+Z != n: 14 | xyz = [X,Y,Z] 15 | output.append(xyz) 16 | 17 | print(output) 18 | -------------------------------------------------------------------------------- /Python/02 - Basic Data Types/Lists.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | N = int(input()) 3 | Output = []; 4 | for i in range(0,N): 5 | ip = input().split(); 6 | if ip[0] == "print": 7 | print(Output) 8 | elif ip[0] == "insert": 9 | Output.insert(int(ip[1]),int(ip[2])) 10 | elif ip[0] == "remove": 11 | Output.remove(int(ip[1])) 12 | elif ip[0] == "pop": 13 | Output.pop(); 14 | elif ip[0] == "append": 15 | Output.append(int(ip[1])) 16 | elif ip[0] == "sort": 17 | Output.sort(); 18 | else: 19 | Output.reverse(); -------------------------------------------------------------------------------- /Python/02 - Basic Data Types/Nested Lists.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | score_list = {} 3 | for _ in range(int(input())): 4 | name = input() 5 | score = float(input()) 6 | 7 | if score in score_list: 8 | score_list[score].append(name) 9 | else: 10 | score_list[score] = [name] 11 | 12 | name_list = [] 13 | 14 | for i in score_list: 15 | name_list.append([i, score_list[i]]) 16 | name_list.sort() 17 | result = name_list[1][1] 18 | result.sort() 19 | print(*result, sep="\n") 20 | -------------------------------------------------------------------------------- /Python/02 - Basic Data Types/Tuples.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | n = int(input()) 3 | integer_list = map(int, input().split()) 4 | 5 | t = tuple(integer_list) 6 | print(hash(t)) 7 | -------------------------------------------------------------------------------- /Python/03 - Strings/Alphabet Rangoli.py: -------------------------------------------------------------------------------- 1 | import string 2 | 3 | alpha = string.ascii_lowercase 4 | 5 | def print_rangoli(size): 6 | # your code goes here 7 | lst = [] 8 | for row in range(size): 9 | to_print = "-".join(alpha[row:size]) 10 | lst.append(to_print[::-1] + to_print[1:]) 11 | width = len(lst[0]) 12 | 13 | for row in range(size - 1, 0 ,-1): 14 | print(lst[row].center(width, "-")) 15 | 16 | for row in range(size): 17 | print(lst[row].center(width, "-")) 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /Python/03 - Strings/Capitalize.py: -------------------------------------------------------------------------------- 1 | # Complete the solve function below. 2 | def solve(s): 3 | for i in s.split(): 4 | s = s.replace(i, i.capitalize()) 5 | return s -------------------------------------------------------------------------------- /Python/03 - Strings/Designer Door Mat.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | if __name__ == '__main__': 3 | N, M = map(int,input().split()) 4 | 5 | for i in range(1,N,2): 6 | print((".|."*i).center(M,'-')) 7 | print('WELCOME'.center(M,'-')) 8 | for i in range(N-2,-1,-2): 9 | print((".|."*i).center(M,'-')) 10 | -------------------------------------------------------------------------------- /Python/03 - Strings/Find a string.py: -------------------------------------------------------------------------------- 1 | def count_substring(string, sub_string): 2 | count = 0 3 | for i in range(len(string)): 4 | if string[i:].startswith(sub_string): 5 | count += 1 6 | return (count) 7 | 8 | 9 | if __name__ == '__main__': 10 | string = input().strip() 11 | sub_string = input().strip() 12 | 13 | count = count_substring(string, sub_string) 14 | print(count) 15 | -------------------------------------------------------------------------------- /Python/03 - Strings/Merge the Tools.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | def merge_the_tools(string, k): 4 | # your code goes here 5 | my_list = [] 6 | my_list = re.findall('[A-Z]{0,%s}' %k, string) 7 | for i in range(len(my_list) - 1): 8 | s = sorted(set(my_list[i]), key = my_list[i].index) 9 | s = ''.join(s) 10 | print(s) 11 | -------------------------------------------------------------------------------- /Python/03 - Strings/Mutations.py: -------------------------------------------------------------------------------- 1 | def mutate_string(string, position, character): 2 | return string[:position] + character + string[position + 1:] 3 | 4 | if __name__ == '__main__': 5 | s = input() 6 | i, c = input().split() 7 | s_new = mutate_string(s, int(i), c) 8 | print(s_new) -------------------------------------------------------------------------------- /Python/03 - Strings/String Formatting.py: -------------------------------------------------------------------------------- 1 | def print_formatted(number): 2 | # your code goes here 3 | for i in range(1, number +1): 4 | width = len(f"{number:b}") 5 | print(f"{i:{width}} {i:{width}o} {i:{width}X} {i:{width}b}") 6 | -------------------------------------------------------------------------------- /Python/03 - Strings/String Split and Join.py: -------------------------------------------------------------------------------- 1 | def split_and_join(line): 2 | # write your code here 3 | if line: 4 | line = line.split(" ") 5 | line = "-".join(line) 6 | return line 7 | if __name__ == '__main__': 8 | line = input() 9 | result = split_and_join(line) 10 | print(result) -------------------------------------------------------------------------------- /Python/03 - Strings/String Validators.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | s = input() 3 | 4 | print(any(i.isalnum() for i in s)) 5 | print(any(i.isalpha() for i in s)) 6 | print(any(i.isdigit() for i in s)) 7 | print(any(i.islower() for i in s)) 8 | print(any(i.isupper() for i in s)) -------------------------------------------------------------------------------- /Python/03 - Strings/Text Alignment.py: -------------------------------------------------------------------------------- 1 | #Replace all ______ with rjust, ljust or center. 2 | 3 | THICKNESS = int(input()) #This must be an odd number 4 | c = 'H' 5 | 6 | # Top Cone 7 | for i in range(THICKNESS): 8 | print((c*i).rjust(THICKNESS-1)+c+(c*i).ljust(THICKNESS-1)) 9 | 10 | # Top Pillars 11 | for i in range(THICKNESS+1): 12 | print((c*THICKNESS).center(THICKNESS*2)+(c*THICKNESS).center(THICKNESS*6)) 13 | 14 | # Middle Belt 15 | for i in range((THICKNESS+1)//2): 16 | print((c*THICKNESS*5).center(THICKNESS*6)) 17 | 18 | # Bottom Pillars 19 | for i in range(THICKNESS+1): 20 | print((c*THICKNESS).center(THICKNESS*2)+(c*THICKNESS).center(THICKNESS*6)) 21 | 22 | # Bottom Cone 23 | for i in range(THICKNESS): 24 | print(((c*(THICKNESS-i-1)).rjust(THICKNESS)+c+(c*(THICKNESS-i-1)).ljust(THICKNESS)).rjust(THICKNESS*6)) -------------------------------------------------------------------------------- /Python/03 - Strings/Text Wrap.py: -------------------------------------------------------------------------------- 1 | import textwrap 2 | 3 | def wrap(string, max_width): 4 | string = [i for i in string] 5 | 6 | for i in range(max_width, len(string) + max_width, max_width+1): 7 | string.insert(i,"\n") 8 | return ("").join(string) 9 | 10 | if __name__ == '__main__': 11 | string, max_width = input(), int(input()) 12 | result = wrap(string, max_width) 13 | print(result) -------------------------------------------------------------------------------- /Python/03 - Strings/The Minion Game.py: -------------------------------------------------------------------------------- 1 | def minion_game(string): 2 | # your code goes here 3 | vowels = "AEIOU" 4 | 5 | kevsc = 0 6 | stusc = 0 7 | 8 | for i in range(len(string)): 9 | if string[i] in vowels: 10 | kevsc += (len(string) - i) 11 | else: 12 | stusc += (len(string) - i) 13 | 14 | if kevsc > stusc: 15 | print("Kevin", kevsc) 16 | elif kevsc < stusc: 17 | print("Stuart", stusc) 18 | else: 19 | print("Draw") 20 | -------------------------------------------------------------------------------- /Python/03 - Strings/What's your name.py: -------------------------------------------------------------------------------- 1 | # 2 | # Complete the 'print_full_name' function below. 3 | # 4 | # The function is expected to return a STRING. 5 | # The function accepts following parameters: 6 | # 1. STRING first 7 | # 2. STRING last 8 | # 9 | 10 | def print_full_name(first, last): 11 | print("Hello {} {}! You just delved into python.".format(first,last)) 12 | 13 | if __name__ == '__main__': 14 | first_name = input() 15 | last_name = input() 16 | print_full_name(first_name, last_name) -------------------------------------------------------------------------------- /Python/03 - Strings/sWAP cASE.py: -------------------------------------------------------------------------------- 1 | def swap_case(s): 2 | return s.swapcase() 3 | 4 | if __name__ == '__main__': 5 | s = input() 6 | result = swap_case(s) 7 | print(result) -------------------------------------------------------------------------------- /Python/04 - Sets/Introductiont to Sets.py: -------------------------------------------------------------------------------- 1 | def average(array): 2 | # your code goes here 3 | s = set(array) 4 | return float(sum(s) / len(s)) 5 | 6 | 7 | if __name__ == '__main__': 8 | n = int(input()) 9 | arr = list(map(int, input().split())) 10 | result = average(arr) 11 | print(result) 12 | -------------------------------------------------------------------------------- /Python/04 - Sets/No Idea.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | integers = list(map(int, input().split())) 3 | n = integers[0] 4 | m = integers[1] 5 | 6 | element_n = input().split() 7 | elements_A = set(input().split()) 8 | elements_B = set(input().split()) 9 | 10 | counter = 0 11 | 12 | for i in element_n: 13 | if i in elements_A: 14 | counter += 1 15 | if i in elements_B: 16 | counter -=1 17 | 18 | print(counter) -------------------------------------------------------------------------------- /Python/04 - Sets/Set - Mutations.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | number_of_elements_in_A = int(input()) 3 | set_of_A = set(map(int, input().split())) 4 | 5 | iteration = int(input()) 6 | 7 | for i in range(iteration): 8 | operation = input().split() 9 | new_set = set(map(int, input().split())) 10 | eval("set_of_A.{}({})".format(operation[0], new_set)) 11 | 12 | print(sum(set_of_A)) -------------------------------------------------------------------------------- /Python/04 - Sets/Set - add().py: -------------------------------------------------------------------------------- 1 | n = int(input()) 2 | names = set([]) 3 | 4 | for i in range(n): 5 | names.add(input()) 6 | 7 | print(len(names)) -------------------------------------------------------------------------------- /Python/04 - Sets/Set - difference().py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | number_of_students_english = int(input()) 3 | roll_numbers_english = set(map(int, input().split())) 4 | 5 | number_of_students_french = int(input()) 6 | roll_numbers_french = set(map(int, input().split())) 7 | 8 | at_least_one_subscription = roll_numbers_english.difference(roll_numbers_french) 9 | print(len(at_least_one_subscription)) -------------------------------------------------------------------------------- /Python/04 - Sets/Set - discard() - remove() , pop().py: -------------------------------------------------------------------------------- 1 | size_set = int(input()) 2 | set0 = set(map(int, input().split())) 3 | iteration_number = int(input()) 4 | 5 | for i in range(iteration_number): 6 | set1 = input().split() 7 | if set1[0] == "pop": 8 | set0.pop() 9 | elif set1[0] == "remove": 10 | set0.remove(int(set1[1])) 11 | elif set1[0] == "discard": 12 | set0.discard(int(set1[1])) 13 | 14 | print(sum(set0)) -------------------------------------------------------------------------------- /Python/04 - Sets/Set - intersection().py: -------------------------------------------------------------------------------- 1 | number_of_students_english = int(input()) 2 | roll_numbers_english = set(map(int, input().split())) 3 | 4 | number_of_students_french = int(input()) 5 | roll_numbers_french = set(map(int, input().split())) 6 | 7 | at_least_one_subscription = roll_numbers_english.intersection(roll_numbers_french) 8 | print(len(at_least_one_subscription)) 9 | -------------------------------------------------------------------------------- /Python/04 - Sets/Set - symmetric_difference().py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | number_of_students_english = int(input()) 3 | roll_numbers_english = set(map(int, input().split())) 4 | 5 | number_of_students_french = int(input()) 6 | roll_numbers_french = set(map(int, input().split())) 7 | 8 | at_least_one_subscription = roll_numbers_english.symmetric_difference(roll_numbers_french) 9 | print(len(at_least_one_subscription)) -------------------------------------------------------------------------------- /Python/04 - Sets/Set - union() Operation.py: -------------------------------------------------------------------------------- 1 | number_of_students_english = int(input()) 2 | roll_numbers_english = set(map(int, input().split())) 3 | 4 | number_of_students_french = int(input()) 5 | roll_numbers_french = set(map(int, input().split())) 6 | 7 | at_least_one_subscription = roll_numbers_english.union(roll_numbers_french) 8 | print(len(at_least_one_subscription)) 9 | -------------------------------------------------------------------------------- /Python/04 - Sets/Symmetric Difference.py: -------------------------------------------------------------------------------- 1 | m = int(input()) 2 | m_integers = set(map(int, input().split())) 3 | n = int(input()) 4 | n_integers = set(map(int, input().split())) 5 | 6 | m_n = m_integers.difference(n_integers) 7 | n_m = n_integers.difference(m_integers) 8 | 9 | union = m_n.union(n_m) 10 | 11 | result = list(union) 12 | result.sort() 13 | 14 | for i in range(len(result)): 15 | print(result[i]) 16 | -------------------------------------------------------------------------------- /Python/05 - Math/Find Angle MBC.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem:https://www.hackerrank.com/challenges/find-angle/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | 7 | import math 8 | 9 | ab = int(input()) 10 | bc = int(input()) 11 | 12 | hypotenuse = math.sqrt(math.pow(ab, 2) + math.pow(bc, 2)) 13 | edge1 = hypotenuse / 2.0 14 | edge2 = bc / 2.0 15 | degree_sign = u'\N{DEGREE SIGN}' 16 | print("{}{}".format(str(int(round(math.degrees(math.acos(edge2 / edge1))))), degree_sign)) 17 | -------------------------------------------------------------------------------- /Python/05 - Math/Integers Come In All Sizes.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem:https://www.hackerrank.com/challenges/python-integers-come-in-all-sizes/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | import math 7 | 8 | a = int(input()) 9 | b = int(input()) 10 | c = int(input()) 11 | d = int(input()) 12 | 13 | print((a**b) + (c**d)) 14 | -------------------------------------------------------------------------------- /Python/05 - Math/Mod Divmod.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/python-mod-divmod/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | 7 | a = int(input()) 8 | b = int(input()) 9 | 10 | print(a // b) 11 | print(a % b) 12 | print(divmod(a, b)) 13 | -------------------------------------------------------------------------------- /Python/05 - Math/Polar Coordinates.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/polar-coordinates/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | 7 | import cmath 8 | 9 | c = eval(input()) 10 | print(abs(c)) 11 | print(cmath.phase(c)) -------------------------------------------------------------------------------- /Python/05 - Math/Power - Mod Power.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/python-power-mod-power/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | import math 7 | 8 | a = int(input()) 9 | b = int(input()) 10 | m = int(input()) 11 | 12 | print(int(math.pow(a, b))) 13 | print(int(math.fmod(math.pow(a, b), m))) 14 | -------------------------------------------------------------------------------- /Python/06 - Itertools/itertools.permutations().py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/itertools-permutations/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | import itertools 7 | 8 | 9 | S = list(map(str, input().split())) 10 | string1 = sorted(S[0]) 11 | number = int(S[1]) 12 | 13 | print(*list(map("".join, itertools.permutations(string1,number))), sep="\n") -------------------------------------------------------------------------------- /Python/06 - Itertools/itertools.product().py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/itertools-product/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | 7 | import itertools 8 | 9 | A = list(map(int, input().split())) 10 | B = list(map(int, input().split())) 11 | 12 | print(*tuple(itertools.product(A,B))) -------------------------------------------------------------------------------- /Python/07 - Collections/Collections.OrderedDict().py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Eda AYDIN 3 | 4 | N: items 5 | """ 6 | from collections import OrderedDict 7 | 8 | N = int(input()) 9 | ordered_dictionary = OrderedDict() 10 | 11 | for i in range(N): 12 | dictionary_input = input() 13 | 14 | if type(int) != int: 15 | split = dictionary_input.split() 16 | 17 | item = split[:-1] 18 | item = " ".join(item) 19 | 20 | cost = split[-1] 21 | cost = "".join(cost) 22 | cost = int(cost) 23 | 24 | if item in ordered_dictionary: 25 | current = ordered_dictionary[item] 26 | current += cost 27 | ordered_dictionary[item] = current 28 | else: 29 | ordered_dictionary[item] = cost 30 | 31 | for key, value in ordered_dictionary.items(): 32 | print(key, value) 33 | -------------------------------------------------------------------------------- /Python/07 - Collections/Collections.deque().py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Eda AYDIN 3 | """ 4 | 5 | from collections import deque 6 | 7 | n = int(input()) 8 | D = deque() 9 | 10 | for i in range(n): 11 | operation, value, *args = input().split() + [""] 12 | eval(f'D.{operation}({value})') 13 | 14 | print(*D) 15 | -------------------------------------------------------------------------------- /Python/07 - Collections/Collections.namedtuple().py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Eda AYDIN 3 | 4 | N: the total number of students 5 | the names of the columns in any order 6 | """ 7 | 8 | from collections import namedtuple 9 | 10 | N = int(input()) 11 | Student = namedtuple("Student", input()) 12 | 13 | result = sum([int(Student(*input().split()).MARKS) for i in range(N)]) / N 14 | 15 | print("{:.2f}".format(result)) 16 | -------------------------------------------------------------------------------- /Python/07 - Collections/Company Logo.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | from collections import Counter 10 | 11 | if __name__ == '__main__': 12 | S = input() 13 | S = sorted(S) 14 | 15 | frequency = Counter(list(S)) 16 | 17 | for key, value in frequency.most_common(3): 18 | print(key, value) 19 | -------------------------------------------------------------------------------- /Python/07 - Collections/DefaultDict Tutorial.py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | from collections import defaultdict 3 | 4 | n, m = map(int,input().split()) 5 | 6 | a = defaultdict(list) 7 | for i in range(1, n + 1): 8 | a[input()].append(i) 9 | 10 | 11 | for i in range(1, m + 1): 12 | key = input() 13 | if len(a[key]) > 0: 14 | print(" ".join(str(c) for c in a[key])) 15 | else: 16 | print(-1) 17 | -------------------------------------------------------------------------------- /Python/07 - Collections/Piling Up!.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Eda AYDIN 3 | """ 4 | 5 | T = int(input()) 6 | answer = [] 7 | 8 | for i in range(T): 9 | size = int(input()) 10 | blocks = list(map(int, input().split())) 11 | 12 | for j in range(size - 1): 13 | if blocks[0] >= blocks[len(blocks) - 1]: 14 | a = blocks[0] 15 | blocks.pop(0) 16 | elif blocks[0] < blocks[len(blocks) - 1]: 17 | a = blocks[len(blocks) - 1] 18 | blocks.pop(len(blocks) - 1) 19 | else: 20 | pass 21 | 22 | if len(blocks) == 1: 23 | answer.append("Yes") 24 | 25 | if (blocks[0] > a) or (blocks[len(blocks) - 1] > a): 26 | answer.append("No") 27 | break 28 | 29 | print("\n".join(answer)) 30 | -------------------------------------------------------------------------------- /Python/07 - Collections/Word Order.py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Eda AYDIN 3 | """ 4 | from collections import Counter 5 | 6 | n = int(input()) 7 | word_list = [] 8 | 9 | for i in range(n): 10 | word_list.append(input().strip()) 11 | 12 | count = Counter(word_list) 13 | 14 | print(len(count)) 15 | print(*count.values()) 16 | -------------------------------------------------------------------------------- /Python/07 - Collections/collections.Counter().py: -------------------------------------------------------------------------------- 1 | """ 2 | Author: Eda AYDIN 3 | 4 | X: number of shoes 5 | List of all the shoe sizes in the shop 6 | N : number of customers 7 | """ 8 | from collections import Counter 9 | 10 | X = int(input()) 11 | stock = Counter(map(int, input().split())) 12 | N = int(input()) 13 | 14 | total_revenue = 0 15 | 16 | for i in range(N): 17 | size, price = map(int, input().split()) 18 | if stock[size]: 19 | total_revenue += price 20 | stock[size] -= 1 21 | 22 | print(total_revenue) 23 | -------------------------------------------------------------------------------- /Python/08 - Data and Time/Calendar Module.py: -------------------------------------------------------------------------------- 1 | import calendar 2 | 3 | month, day, year = map(int, input().split()) 4 | 5 | print(calendar.day_name[calendar.weekday(year, month, day)].upper()) 6 | -------------------------------------------------------------------------------- /Python/08 - Data and Time/Time Delta.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | from datetime import datetime 5 | 6 | 7 | # Complete the time_delta function below. 8 | def time_delta(t1, t2): 9 | time1 = datetime.strptime(t1, '%a %d %b %Y %H:%M:%S %z') 10 | time2 = datetime.strptime(t2, '%a %d %b %Y %H:%M:%S %z') 11 | 12 | return str(int(abs((time1 - time2).total_seconds()))) 13 | 14 | 15 | if __name__ == '__main__': 16 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 17 | 18 | t = int(input()) 19 | for t_itr in range(t): 20 | t1 = input() 21 | t2 = input() 22 | delta = time_delta(t1, t2) 23 | fptr.write(delta + '\n') 24 | 25 | fptr.close() 26 | -------------------------------------------------------------------------------- /Python/09 - Errors and Exceptions/Exceptions.py: -------------------------------------------------------------------------------- 1 | for i in range(int(input())): 2 | try: 3 | a, b = map(int, input().split()) 4 | print(a // b) 5 | except ZeroDivisionError as z: 6 | print(f"Error Code: {z}") 7 | except ValueError as v: 8 | print(f"Error Code: {v}") 9 | -------------------------------------------------------------------------------- /Python/09 - Errors and Exceptions/Incorrect Regex.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | for i in range(int(input())): 4 | try: 5 | a = re.compile(input()) 6 | print("True") 7 | except Exception: 8 | print("False") 9 | -------------------------------------------------------------------------------- /Python/12 - Python Functionals/Map and Lambda Function.py: -------------------------------------------------------------------------------- 1 | cube = lambda x: x**3 # complete the lambda function 2 | 3 | def fibonacci(n): 4 | # return a list of fibonacci numbers 5 | storage = [0,1] 6 | for i in range(2,n): 7 | storage.append(storage[i -1] + storage[i - 2]) 8 | return storage[0:n] 9 | 10 | if __name__ == '__main__': 11 | n = int(input()) 12 | print(list(map(cube, fibonacci(n)))) -------------------------------------------------------------------------------- /Python/12 - Python Functionals/Reduce Function.py: -------------------------------------------------------------------------------- 1 | from fractions import Fraction 2 | from functools import reduce 3 | 4 | 5 | def product(fracs): 6 | t = Fraction(reduce(lambda x, y: x * y, fracs)) # complete this line with a reduce statement 7 | return t.numerator, t.denominator 8 | 9 | 10 | if __name__ == '__main__': 11 | fracs = [] 12 | for _ in range(int(input())): 13 | fracs.append(Fraction(*map(int, input().split()))) 14 | result = product(fracs) 15 | print(*result) 16 | -------------------------------------------------------------------------------- /Python/12 - Python Functionals/Validating Email Addressess with a Filter.py: -------------------------------------------------------------------------------- 1 | def fun(s): 2 | # return True if s is a valid email, else return False 3 | try: 4 | username, url = s.split("@") 5 | website, extension = url.split(".") 6 | except ValueError: 7 | return False 8 | 9 | if username.replace("-", "").replace("_", "").isalnum() is False: 10 | return False 11 | 12 | elif website.isalnum() is False: 13 | return False 14 | 15 | elif len(extension) > 3: 16 | return False 17 | 18 | else: 19 | return True 20 | 21 | 22 | def filter_mail(emails): 23 | return list(filter(fun, emails)) 24 | 25 | 26 | if __name__ == '__main__': 27 | n = int(input()) 28 | emails = [] 29 | for _ in range(n): 30 | emails.append(input()) 31 | 32 | filtered_emails = filter_mail(emails) 33 | filtered_emails.sort() 34 | print(filtered_emails) 35 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Detect Floating Point Number.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | for _ in range(int(input())): 4 | print(re.search(r'^([-\+])?\d*\.\d+$', input()) is not None) 5 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Detect HTML Tags, Attributes and Attribute Values.py: -------------------------------------------------------------------------------- 1 | from html.parser import HTMLParser 2 | 3 | 4 | class MyHTMLParser(HTMLParser): 5 | def handle_starttag(self, tag, attrs): 6 | print(tag) 7 | for attr, value in attrs: 8 | print("->", attr, ">", value) 9 | 10 | def handle_startendtag(self, tag, attrs): 11 | print(tag) 12 | for attr, value in attrs: 13 | print("->", attr, ">", value) 14 | 15 | 16 | html = '' 17 | for _ in range(int(input())): 18 | html += input().rstrip() + '\n' 19 | 20 | parser = MyHTMLParser() 21 | parser.feed(html) 22 | parser.close() 23 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Group(), Groups() - Groupdict().py: -------------------------------------------------------------------------------- 1 | import re 2 | m = re.findall(r"([A-Za-z0-9])\1+",input()) 3 | if m: 4 | print(m[0]) 5 | else: 6 | print(-1) -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/HTML Parser - Part 1.py: -------------------------------------------------------------------------------- 1 | from html.parser import HTMLParser 2 | 3 | 4 | class MyHTMLParser(HTMLParser): 5 | def handle_starttag(self, tag, attrs): 6 | print('Start :', tag) 7 | for ele in attrs: 8 | print('->', ele[0], '>', ele[1]) 9 | 10 | def handle_endtag(self, tag): 11 | print('End :', tag) 12 | 13 | def handle_startendtag(self, tag, attrs): 14 | print('Empty :', tag) 15 | for ele in attrs: 16 | print('->', ele[0], '>', ele[1]) 17 | 18 | 19 | parser = MyHTMLParser() 20 | for _ in range(int(input())): 21 | parser.feed(input()) 22 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/HTML Parser - Part 2.py: -------------------------------------------------------------------------------- 1 | from html.parser import HTMLParser 2 | 3 | 4 | class MyHTMLParser(HTMLParser): 5 | 6 | def handle_comment(self, data): 7 | if len(data.split('\n')) != 1: 8 | print(">>> Multi-line Comment") 9 | else: 10 | print(">>> Single-line Comment") 11 | print(data.replace("\r", "\n")) 12 | 13 | def handle_data(self, data): 14 | if data.strip(): 15 | print(">>> Data") 16 | print(data) 17 | 18 | 19 | html = "" 20 | for i in range(int(input())): 21 | html += input().rstrip() 22 | html += '\n' 23 | 24 | parser = MyHTMLParser() 25 | parser.feed(html) 26 | parser.close() 27 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Hex Color Code.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | T = int(input()) 4 | in_css = False 5 | for _ in range(T): 6 | s = input() 7 | if '{' in s: 8 | in_css = True 9 | elif '}' in s: 10 | in_css = False 11 | elif in_css: 12 | for color in re.findall('#[0-9a-fA-F]{3,6}', s): 13 | print(color) -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Matrix Script.py: -------------------------------------------------------------------------------- 1 | import math 2 | import os 3 | import random 4 | import re 5 | import sys 6 | 7 | first_multiple_input = input().rstrip().split() 8 | 9 | n = int(first_multiple_input[0]) 10 | m = int(first_multiple_input[1]) 11 | 12 | matrix = [] 13 | 14 | for _ in range(n): 15 | matrix_item = input() 16 | matrix.append(matrix_item) 17 | 18 | # start 19 | matrix = list(zip(*matrix)) 20 | 21 | sample = str() 22 | 23 | for words in matrix: 24 | for char in words: 25 | sample += char 26 | 27 | print(re.sub(r'(?<=\w)([^\w\d]+)(?=\w)', ' ', sample)) -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Re.findall - Re.finditer().py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | vowels = "aeiou" 4 | constants = "qwrtypsdfghjklzxcvbnm" 5 | 6 | pattern = r"(?<=[%s])([%s]{2,})[%s]" % (constants, vowels, constants) 7 | 8 | m = re.findall(pattern, input(), flags=re.I) 9 | if m: 10 | print("\n".join(m)) 11 | else: 12 | print(-1) 13 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Re.split().py: -------------------------------------------------------------------------------- 1 | regex_pattern = r",|\." # Do not delete 'r'. 2 | 3 | import re 4 | print("\n".join(re.split(regex_pattern, input()))) -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Re.start() - Re.end().py: -------------------------------------------------------------------------------- 1 | # Enter your code here. Read input from STDIN. Print output to STDOUT 2 | import re 3 | 4 | S, k = input(), input() 5 | matches = re.finditer(r'(?=(' + k + '))', S) 6 | 7 | anymatch = False 8 | 9 | for match in matches: 10 | anymatch = True 11 | print((match.start(1), match.end(1) - 1)) 12 | 13 | if not anymatch: 14 | print((-1,-1)) 15 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Regex Substitution.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | 4 | def change(match): 5 | if match.group(1) == "&&": 6 | return "and" 7 | else: 8 | return "or" 9 | 10 | 11 | for _ in range(int(input())): 12 | pattern = r"(?<= )(\|\||&&)(?= )" 13 | print(re.sub(pattern, change, input())) 14 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Validating Credit Card Numbers.py: -------------------------------------------------------------------------------- 1 | import re 2 | for i in range(int(input())): 3 | S = input().strip() 4 | pre_match = re.search(r'^[456]\d{3}(-?)\d{4}\1\d{4}\1\d{4}$',S) 5 | if pre_match: 6 | processed_string = "".join(pre_match.group(0).split('-')) 7 | final_match = re.search(r'(\d)\1{3,}',processed_string) 8 | if final_match: 9 | print('Invalid') 10 | else : 11 | print('Valid') 12 | else: 13 | print('Invalid') -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Validating Postal Codes.py: -------------------------------------------------------------------------------- 1 | regex_integer_in_range = r"^[1-9][\d]{5}$" # Do not delete 'r'. 2 | regex_alternating_repetitive_digit_pair =r"(\d)(?=\d\1)" # Do not delete 'r'. 3 | 4 | 5 | import re 6 | P = input() 7 | 8 | print (bool(re.match(regex_integer_in_range, P)) 9 | and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2) -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Validating Roman Numerals.py: -------------------------------------------------------------------------------- 1 | thousand = "M{0,3}" 2 | hundred = "(C[MD]|D?C{0,3})" 3 | ten = "(X[CL]|L?X{0,3})" 4 | digit = "(I[VX]|V?I{0,3})" 5 | 6 | regex_pattern = r"%s%s%s%s$" % (thousand, hundred, ten, digit) # Do not delete 'r'. 7 | 8 | import re 9 | 10 | print(str(bool(re.match(regex_pattern, input())))) 11 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Validating UID.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | for i in range(int(input())): 4 | N = input().strip() 5 | if N.isalnum() and len(N) == 10: 6 | if bool(re.search(r'(.*[A-Z]){2,}',N)) and bool(re.search(r'(.*[0-9]){3,}',N)): 7 | if re.search(r'.*(.).*\1+.*',N): 8 | print('Invalid') 9 | else: 10 | print('Valid') 11 | else: 12 | print('Invalid') 13 | else: 14 | print('Invalid') -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Validating and Parsing Email Addresses.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | N = int(input()) 4 | 5 | for i in range(N): 6 | name, email = input().split() 7 | pattern = "<[a-z][a-zA-Z0-9\-\.\_]+@[a-zA-Z]+\.[a-zA-Z]{1,3}>" 8 | if bool(re.match(pattern, email)): 9 | print(name, email) 10 | -------------------------------------------------------------------------------- /Python/13 - Regex and Parsing/Validating phone numbers.py: -------------------------------------------------------------------------------- 1 | import re 2 | 3 | N = int(input()) 4 | 5 | for i in range(N): 6 | number = input() 7 | if 2 <= len(number) <= 15 and number.isdigit(): 8 | output = re.findall(r"^[789]\d{9}$", number) 9 | if len(output) == 1: 10 | print("YES") 11 | else: 12 | print("NO") 13 | else: 14 | print("NO") 15 | -------------------------------------------------------------------------------- /Python/14 - XML/XML 1 - Find the Score.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import xml.etree.ElementTree as etree 3 | 4 | 5 | def get_attr_number(node): 6 | # your code goes here 7 | count = 0 8 | for tag in node: 9 | count = count + get_attr_number(tag) 10 | return count + len(node.attrib) 11 | 12 | 13 | if __name__ == '__main__': 14 | sys.stdin.readline() 15 | xml = sys.stdin.read() 16 | tree = etree.ElementTree(etree.fromstring(xml)) 17 | root = tree.getroot() 18 | print(get_attr_number(root)) -------------------------------------------------------------------------------- /Python/14 - XML/XML 2 - Find the Maximum Depth.py: -------------------------------------------------------------------------------- 1 | import xml.etree.ElementTree as etree 2 | 3 | maxdepth = 0 4 | 5 | 6 | def depth(elem, level): 7 | global maxdepth 8 | # your code goes here 9 | if level == maxdepth: 10 | maxdepth +=1 11 | for child in elem: 12 | depth(child,level + 1) 13 | 14 | 15 | if __name__ == '__main__': 16 | n = int(input()) 17 | xml = "" 18 | for i in range(n): 19 | xml = xml + input() + "\n" 20 | tree = etree.ElementTree(etree.fromstring(xml)) 21 | depth(tree.getroot(), -1) 22 | print(maxdepth) -------------------------------------------------------------------------------- /Python/15 - Closures and Decorators/Decorators 2 - Name Directory.py: -------------------------------------------------------------------------------- 1 | import operator 2 | 3 | def person_lister(f): 4 | def inner(people): 5 | # complete the function 6 | return [f(p) for p in sorted(people, key = lambda x: (int(x[2])))] 7 | return inner 8 | 9 | @person_lister 10 | def name_format(person): 11 | return ("Mr. " if person[3] == "M" else "Ms. ") + person[0] + " " + person[1] 12 | 13 | if __name__ == '__main__': 14 | people = [input().split() for i in range(int(input()))] 15 | print(*name_format(people), sep='\n') -------------------------------------------------------------------------------- /Python/15 - Closures and Decorators/Standardize Mobile Number Using Decorators.py: -------------------------------------------------------------------------------- 1 | def wrapper(f): 2 | def fun(l): 3 | # complete the function 4 | f(['+91 ' + c[-10:-5] + ' ' + c[-5:] for c in l]) 5 | return fun 6 | 7 | @wrapper 8 | def sort_phone(l): 9 | print(*sorted(l), sep='\n') 10 | 11 | if __name__ == '__main__': 12 | l = [input() for _ in range(int(input()))] 13 | sort_phone(l) 14 | 15 | 16 | -------------------------------------------------------------------------------- /Python/16 - NumPy/Array Mathematics.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | N, M = map(int, input().split()) 4 | 5 | A = numpy.array([list(map(int, input().split())) for n in range(N)]) 6 | B = numpy.array([list(map(int, input().split())) for n in range(N)]) 7 | 8 | print(A + B) 9 | print(A - B) 10 | print(A * B) 11 | print(A // B) 12 | print(A % B) 13 | print(A ** B) -------------------------------------------------------------------------------- /Python/16 - NumPy/Arrays.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | def arrays(arr): 4 | # complete this function 5 | return(numpy.array(arr[::-1], float)) 6 | arr = input().strip().split(' ') 7 | result = arrays(arr) 8 | print(result) -------------------------------------------------------------------------------- /Python/16 - NumPy/Concatenate.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | P, N, M = map(int,input().split()) 3 | A = numpy.array([input().split() for _ in range(P)],int) 4 | B = numpy.array([input().split() for _ in range(N)],int) 5 | print(numpy.concatenate((A, B), axis = 0)) -------------------------------------------------------------------------------- /Python/16 - NumPy/Dot and Cross.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | n = int(input()) 4 | a = numpy.array([input().split() for _ in range(n)], int) 5 | b = numpy.array([input().split() for _ in range(n)], int) 6 | print(numpy.dot(a, b)) -------------------------------------------------------------------------------- /Python/16 - NumPy/Eye and Identity.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | numpy.set_printoptions(sign=' ') 4 | print(numpy.eye(*map(int, input().split()))) -------------------------------------------------------------------------------- /Python/16 - NumPy/Floor, Ceil and Rint.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | numpy.set_printoptions(sign=' ') 4 | 5 | array = numpy.array(input().split(),float) 6 | 7 | print(numpy.floor(array)) 8 | print(numpy.ceil(array)) 9 | print(numpy.rint(array)) -------------------------------------------------------------------------------- /Python/16 - NumPy/Inner and Outer.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | A = numpy.array(input().split(), int) 4 | B = numpy.array(input().split(), int) 5 | print(numpy.inner(A, B), numpy.outer(A, B), sep='\n') -------------------------------------------------------------------------------- /Python/16 - NumPy/Linear Algebra.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | N = int(input()) 3 | A = numpy.array([input().split() for _ in range(N)], float) 4 | print(round(numpy.linalg.det(A),2)) -------------------------------------------------------------------------------- /Python/16 - NumPy/Mean, Var, and Std.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | 4 | n, m = [int(x) for x in input().strip().split()] 5 | 6 | 7 | arr = np.array([[int(x) for x in input().strip().split()] for _ in range(n)]) 8 | 9 | 10 | print(np.mean(arr, axis = 1)) 11 | print(np.var(arr, axis = 0)) 12 | print(np.round(np.std(arr), decimals = 11)) -------------------------------------------------------------------------------- /Python/16 - NumPy/Min and Max.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | n, m = [int(x) for x in input().strip().split()] 4 | array = np.array([[int(x) for x in input().strip().split()] for _ in range(n)]) 5 | print(np.max(np.min(array, axis = 1))) -------------------------------------------------------------------------------- /Python/16 - NumPy/Polynomials.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | poly = [float(x) for x in input().split()] 4 | x = float(input()) 5 | 6 | print(numpy.polyval(poly, x)) -------------------------------------------------------------------------------- /Python/16 - NumPy/Shape and Reshape.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | print(np.array(input().split(), int).reshape(3,3)) 4 | 5 | -------------------------------------------------------------------------------- /Python/16 - NumPy/Sum and Prod.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | N, M = map(int, input().split()) 4 | A = numpy.array([input().split() for _ in range(N)], int) 5 | print(numpy.prod(numpy.sum(A, axis=0), axis=0)) -------------------------------------------------------------------------------- /Python/16 - NumPy/Transpose and Flatten.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | n, m = map(int, input().split()) 3 | 4 | storage = numpy.array([input().strip().split() for _ in range(n)], int) 5 | print (storage.transpose()) 6 | print (storage.flatten()) -------------------------------------------------------------------------------- /Python/16 - NumPy/Zeros and Ones.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | N = tuple(map(int, input().split())) 4 | print(numpy.zeros(N, int)) 5 | print(numpy.ones(N, int)) -------------------------------------------------------------------------------- /Python/17 - Debugging/Default Arguments.py: -------------------------------------------------------------------------------- 1 | class EvenStream(object): 2 | def __init__(self): 3 | self.current = 0 4 | 5 | def get_next(self): 6 | to_return = self.current 7 | self.current += 2 8 | return to_return 9 | 10 | class OddStream(object): 11 | def __init__(self): 12 | self.current = 1 13 | 14 | def get_next(self): 15 | to_return = self.current 16 | self.current += 2 17 | return to_return 18 | 19 | def print_from_stream(n, stream=None): 20 | if stream is None: 21 | stream = EvenStream() 22 | for _ in range(n): 23 | print(stream.get_next()) 24 | 25 | 26 | queries = int(input()) 27 | for _ in range(queries): 28 | stream_name, n = input().split() 29 | n = int(n) 30 | if stream_name == "even": 31 | print_from_stream(n) 32 | else: 33 | print_from_stream(n, OddStream()) 34 | -------------------------------------------------------------------------------- /Python/17 - Debugging/Words Score.py: -------------------------------------------------------------------------------- 1 | def is_vowel(letter): 2 | return letter in ['a', 'e', 'i', 'o', 'u', 'y'] 3 | 4 | def score_words(words): 5 | score = 0 6 | for word in words: 7 | num_vowels = 0 8 | for letter in word: 9 | if is_vowel(letter): 10 | num_vowels += 1 11 | if num_vowels % 2 == 0: 12 | score += 2 13 | else: 14 | score += 1 15 | return score 16 | 17 | 18 | n = int(input()) 19 | words = input().split() 20 | print(score_words(words)) -------------------------------------------------------------------------------- /SQL/Advanced Join/Placements.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: https://www.hackerrank.com/challenges/placements 3 | */ 4 | SELECT S.NAME 5 | FROM STUDENTS AS S 6 | INNER JOIN PACKAGES AS P1 ON S.ID = P1.ID 7 | INNER JOIN FRIENDS AS F ON S.ID = F.ID 8 | INNER JOIN PACKAGES AS P2 ON F.FRIEND_ID = P2.ID 9 | WHERE P2.SALARY > P1.SALARY 10 | ORDER BY P2.SALARY -------------------------------------------------------------------------------- /SQL/Advanced Join/SQL Project Planning.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: https://www.hackerrank.com/challenges/sql-projects 3 | 4 | Author: Eda AYDIN 5 | */ 6 | SELECT START_DATE,MIN(END_DATE) 7 | FROM (SELECT START_DATE 8 | FROM PROJECTS 9 | WHERE START_DATE NOT IN (SELECT END_DATE 10 | FROM PROJECTS)) AS SD, 11 | (SELECT END_DATE 12 | FROM PROJECTS 13 | WHERE END_DATE NOT IN (SELECT START_DATE 14 | FROM PROJECTS)) AS ED 15 | WHERE START_DATE < END_DATE 16 | GROUP BY START_DATE 17 | ORDER BY DATEDIFF(MIN(END_DATE), START_DATE),START_DATE -------------------------------------------------------------------------------- /SQL/Advanced Join/Symmetric Pairs.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Problem:https://www.hackerrank.com/challenges/symmetric-pairs 3 | */ 4 | SELECT F1.X, F1.Y 5 | FROM FUNCTIONS AS F1 6 | JOIN FUNCTIONS AS F2 ON F1.X = F2.Y AND F1.Y = F2.X 7 | GROUP BY F1.X, F1.Y 8 | HAVING COUNT(F1.X) >1 OR F1.X < F1.Y 9 | ORDER BY F1.X -------------------------------------------------------------------------------- /SQL/Advanced Select/Binary Tree Nodes.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Problem:https://www.hackerrank.com/challenges/binary-search-tree-1 3 | */ 4 | SELECT N, CASE WHEN P IS NULL THEN "Root" 5 | WHEN EXISTS(SELECT P 6 | FROM BST 7 | WHERE B.N = P 8 | ) THEN "Inner" 9 | ELSE "Leaf" 10 | END 11 | FROM BST AS B 12 | ORDER BY N -------------------------------------------------------------------------------- /SQL/Advanced Select/New Companies.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: https://www.hackerrank.com/challenges/the-company 3 | 4 | Author: Eda AYDIN 5 | */ 6 | SELECT C.COMPANY_CODE, C.FOUNDER, 7 | COUNT(DISTINCT L.LEAD_MANAGER_CODE), 8 | COUNT(DISTINCT S.SENIOR_MANAGER_CODE), 9 | COUNT(DISTINCT M.MANAGER_CODE), 10 | COUNT(DISTINCT E.EMPLOYEE_CODE) 11 | FROM COMPANY AS C, 12 | LEAD_MANAGER AS L, 13 | SENIOR_MANAGER AS S, 14 | MANAGER AS M, 15 | EMPLOYEE AS E 16 | WHERE C.COMPANY_CODE = L.COMPANY_CODE 17 | AND L.LEAD_MANAGER_CODE = S.LEAD_MANAGER_CODE 18 | AND S.SENIOR_MANAGER_CODE = M.SENIOR_MANAGER_CODE 19 | AND M.MANAGER_CODE = E.MANAGER_CODE 20 | GROUP BY C.COMPANY_CODE, C.FOUNDER 21 | ORDER BY COMPANY_CODE -------------------------------------------------------------------------------- /SQL/Advanced Select/Occupations.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: https://www.hackerrank.com/challenges/occupations 3 | Author: Eda AYDIN 4 | */ 5 | 6 | SET @r1=0, @r2=0, @r3=0, @r4=0; 7 | SELECT MIN(d), MIN(p), MIN(s), MIN(a) 8 | FROM (SELECT CASE WHEN OCCUPATION = 'DOCTOR' THEN (@r1 := @r1 + 1) 9 | WHEN OCCUPATION = 'PROFESSOR' THEN (@r2 := @r2 + 1) 10 | WHEN OCCUPATION = 'SINGER' THEN (@r3 := @r3 + 1) 11 | WHEN OCCUPATION = 'ACTOR' THEN (@r4 := @r4 + 1) END AS row_index, 12 | CASE WHEN OCCUPATION = 'DOCTOR' THEN NAME END AS d, 13 | CASE WHEN OCCUPATION = 'PROFESSOR' THEN NAME END AS p, 14 | CASE WHEN OCCUPATION = 'SINGER' THEN NAME END AS s, 15 | CASE WHEN OCCUPATION = 'ACTOR' THEN NAME END AS a 16 | FROM OCCUPATIONS 17 | ORDER BY NAME 18 | ) AS t 19 | GROUP BY row_index -------------------------------------------------------------------------------- /SQL/Advanced Select/The PADS.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Problem: https://www.hackerrank.com/challenges/the-pads/ 3 | Author: Eda AYDIN 4 | */ 5 | SELECT CONCAT(NAME, "(",SUBSTRING(OCCUPATION,1,1), ")") 6 | FROM OCCUPATIONS 7 | ORDER BY NAME; 8 | 9 | SELECT CONCAT("There are a total of ", COUNT(OCCUPATION), " ",LOWER(OCCUPATION),"s.") AS TOTAL 10 | FROM OCCUPATIONS 11 | GROUP BY OCCUPATION 12 | ORDER BY TOTAL -------------------------------------------------------------------------------- /SQL/Advanced Select/Type of Triangle.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Write a query identifying the type of each record in the TRIANGLES table 3 | using its three side lengths. 4 | 5 | A = B : ISOSCELES 6 | A = B = C: EQULIATERAL TRIANGLE 7 | A != B != C : SCALENE TRIANGLE 8 | A + B < C : IT IS NOT TRIANGLE 9 | 10 | Author: Eda AYDIN 11 | */ 12 | 13 | SELECT CASE WHEN (A+B<=C OR A+C<=B OR B+C<=A) THEN "Not A TriangLe" 14 | WHEN (A=B AND B=C) THEN "Equilateral" 15 | WHEN (A=B OR B=C OR A=C) THEN "Isosceles" 16 | ELSE "Scalene" 17 | END 18 | FROM TRIANGLES 19 | -------------------------------------------------------------------------------- /SQL/Aggregation/Average Population.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the average population of all cities in CITY, rounded down to the nearest integer. 5 | */ 6 | 7 | SELECT FLOOR(AVG(POPULATION)) 8 | FROM CITY 9 | 10 | /* 11 | 454250 12 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Japan Population.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the sum of the populations for all Japanese cities in City. The COUNTRYCODE for Japan is JPN. 5 | */ 6 | 7 | SELECT SUM(POPULATION) 8 | FROM CITY 9 | WHERE COUNTRYCODE = "JPN" 10 | 11 | /* 12 | 879196 13 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Population Density Difference.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the difference between the maximum and minimum populations in CITY. 5 | */ 6 | 7 | SELECT MAX(POPULATION) - MIN(POPULATION) 8 | FROM CITY 9 | 10 | /* 11 | 4695354 12 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Revising Aggregations - Averages.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the average population of all cities in CITY where District California 5 | */ 6 | 7 | SELECT AVG(POPULATION) 8 | FROM CITY 9 | WHERE DISTRICT = "CALIFORNIA" 10 | 11 | /* 12 | 113000.667 13 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Revising Aggregations - The Count Function.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query a count of the number of cities in CITY having a Population larger than 100,000 5 | */ 6 | 7 | SELECT COUNT(*) 8 | FROM CITY 9 | WHERE POPULATION > 100000; 10 | 11 | /* 12 | 6 13 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Revising Aggregations - The Sum Function.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the total population of all cities in CITY where District is California. 5 | */ 6 | 7 | SELECT SUM(POPULATION) 8 | FROM CITY 9 | WHERE DISTRICT = "CALIFORNIA" 10 | 11 | /* 12 | 339002 13 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/The Blunder.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Write a query calculating the amount of error and round it up to the next integer. 5 | Employees: ID, Name, SALARY 6 | */ 7 | 8 | SELECT CEIL(AVG(SALARY) - AVG(REPLACE(SALARY, "0",""))) 9 | FROM EMPLOYEES 10 | 11 | /* 12 | 2253 13 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Top Earners.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Write a query to find the maximum total earnings for all employees as well as the 5 | total number of employees who have maximum total earnings. 6 | Then print these values as 2 space-separated integers. 7 | 8 | Employee: employee_id, name, months, salary 9 | */ 10 | 11 | SELECT SALARY * MONTHS AS EARNINGS, COUNT(*) 12 | FROM EMPLOYEE 13 | GROUP BY EARNINGS 14 | ORDER BY EARNINGS DESC 15 | LIMIT 1 16 | 17 | /* 18 | 108064 7 19 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 13.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SELECT TRUNCATE (SUM(LAT_N),4) 6 | FROM STATION 7 | WHERE LAT_N BETWEEN 38.7880 AND 137.2345 8 | 9 | /* 10 | 36354.8135 11 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 14.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SELECT TRUNCATE(MAX(LAT_N),4) 6 | FROM STATION 7 | WHERE LAT_N < 137.2345 8 | 9 | /* 10 | 137.0193 11 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 15.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SELECT ROUND(LONG_W, 4) 6 | FROM STATION 7 | WHERE LAT_N < 137.2345 8 | ORDER BY LAT_N DESC 9 | LIMIT 1 10 | 11 | /* 12 | 117.2465 13 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 16.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SELECT ROUND(MIN(LAT_N),4) 6 | FROM STATION 7 | WHERE LAT_N > 38.7780 8 | 9 | /* 10 | 38.8526 11 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 17.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SELECT ROUND(LONG_W,4) 6 | FROM STATION 7 | WHERE LAT_N > 38.7780 8 | ORDER BY LAT_N 9 | LIMIT 1 10 | 11 | /* 12 | 70.1378 13 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 18.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SELECT ROUND(ABS(MAX(LAT_N) - MIN(LAT_N)) + ABS(MAX(LONG_W) - MIN(LONG_W)), 4) 6 | FROM STATION 7 | 8 | /* 9 | 259.6859 10 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 19.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SELECT ROUND(SQRT(POWER(MAX(LAT_N) - MIN(LAT_N),2) + POWER(MAX(LONG_W) - MIN(LONG_W),2)), 4) 6 | FROM STATION 7 | 8 | /* 9 | 184.1616 10 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 2.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the following two values from the STATION table: 5 | 6 | The sum of all values in LAT_N rounded to a scale of 2 decimal places. 7 | The sum of all values in LONG_W rounded to a scale of 2 decimal places. 8 | 9 | */ 10 | 11 | SELECT ROUND(SUM(LAT_N),2), ROUND(SUM(LONG_W),2) 12 | FROM STATION 13 | 14 | /* 15 | 42850.04 47381.48 16 | */ -------------------------------------------------------------------------------- /SQL/Aggregation/Weather Observation Station 20.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | 5 | SET @index := -1; 6 | SELECT ROUND(AVG(S2.LAT_N), 4) 7 | FROM ( 8 | SELECT @index := @index + 1 AS INDEX_, S.LAT_N 9 | FROM STATION AS S 10 | ORDER BY S.LAT_N 11 | ) AS S2 12 | WHERE S2.INDEX_ IN (FLOOR(@index / 2), CEIL(@index / 2)) 13 | 14 | /* 15 | 83.8913 16 | */ -------------------------------------------------------------------------------- /SQL/Alternative Queries/Draw The Triangle 1.sql: -------------------------------------------------------------------------------- 1 | SET @NUMBER = 21; 2 | SELECT REPEAT("* ", @NUMBER := @NUMBER - 1) 3 | FROM INFORMATION_SCHEMA.TABLES -------------------------------------------------------------------------------- /SQL/Alternative Queries/Draw The Triangle 2.sql: -------------------------------------------------------------------------------- 1 | SET @NUMBER = 0; 2 | SELECT REPEAT("* ", @NUMBER := @NUMBER + 1) 3 | FROM INFORMATION_SCHEMA.TABLES 4 | LIMIT 20; -------------------------------------------------------------------------------- /SQL/Alternative Queries/Print Prime Numbers.sql: -------------------------------------------------------------------------------- 1 | SET @NUMBER = 1; 2 | SET @DIVISOR = 1; 3 | SELECT GROUP_CONCAT(n SEPARATOR '&') 4 | FROM (SELECT @NUMBER := @NUMBER + 1 AS N 5 | FROM INFORMATION_SCHEMA.TABLES AS T1, INFORMATION_SCHEMA.TABLES AS T2 6 | LIMIT 1000 7 | ) AS N1 8 | WHERE NOT EXISTS(SELECT * 9 | FROM (SELECT @DIVISOR := @DIVISOR + 1 AS D 10 | FROM INFORMATION_SCHEMA.TABLES AS T3, INFORMATION_SCHEMA.TABLES AS T4 11 | LIMIT 1000 12 | ) AS N2 13 | WHERE MOD(N, D) = 0 AND N <> D) -------------------------------------------------------------------------------- /SQL/Basic Join/African Cities.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | SELECT CITY.NAME 5 | FROM COUNTRY, CITY 6 | WHERE CITY.COUNTRYCODE = COUNTRY.CODE AND COUNTRY.CONTINENT = "AFRICA"; 7 | 8 | /* 9 | Qina 10 | Warraq al-Arab 11 | Kempton Park 12 | Alberton 13 | Klerksdorp 14 | Uitenhage 15 | Brakpan 16 | Libreville 17 | */ -------------------------------------------------------------------------------- /SQL/Basic Join/Average Population of Each Continent.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | SELECT COUNTRY.CONTINENT, FLOOR(AVG(CITY.POPULATION)) 5 | FROM COUNTRY 6 | JOIN CITY ON CITY.COUNTRYCODE = COUNTRY.CODE 7 | GROUP BY COUNTRY.CONTINENT; 8 | 9 | /* 10 | Asia 693038 11 | Oceania 109189 12 | Europe 175138 13 | South America 147435 14 | Africa 274439 15 | */ -------------------------------------------------------------------------------- /SQL/Basic Join/Contest Leaderboard.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Write a query to print the hacker_id, name, and total score of the hackers ordered 5 | by the descending score. 6 | If more than one hacker achieved the same total score, then sort the result by ascending hacker_id. 7 | Exclude all hackers with a total score of 0 from your result. 8 | 9 | Hackers: hacker_id, name 10 | Submissions: submission_id, hacker_id, challenge_id, score 11 | */ 12 | SELECT H.hacker_id, H.name, SUM(Sscore) 13 | FROM Hackers H 14 | INNER JOIN ( 15 | SELECT S.hacker_id, MAX(score) AS Sscore 16 | FROM Submissions S 17 | GROUP BY S.hacker_id, S.challenge_id) 18 | S2 ON H.hacker_id = S2.hacker_id 19 | GROUP BY H.hacker_id, H.name 20 | HAVING SUM(Sscore) > 0 21 | ORDER BY SUM(Sscore) DESC, H.hacker_id ASC; -------------------------------------------------------------------------------- /SQL/Basic Join/Ollivanders Inventory.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Problem: Write a query to print the id, age, coins_needed, and power of the wands that Ron's 5 | interested in, sorted in order of descending power. If more than one wand has same power, 6 | sort the result in order of descending age. 7 | 8 | Wands : id, code, coins_needed, power 9 | Wands_Property : code, age, is_evil 10 | */ 11 | SELECT W.id, WP.age, W.coins_needed,W.power 12 | FROM wands W 13 | JOIN wands_property WP ON W.code = WP.code 14 | WHERE WP.is_evil = 0 AND W.coins_needed = ( 15 | SELECT Min(W1.coins_needed) 16 | FROM wands W1 17 | JOIN wands_property WP1 ON W1.code = WP1.code 18 | WHERE WP.age = WP1.age AND W.power = W1.power) 19 | ORDER BY W.power DESC,WP.age DESC; -------------------------------------------------------------------------------- /SQL/Basic Join/Population Census.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | SELECT SUM(CITY.POPULATION) 5 | FROM COUNTRY 6 | LEFT JOIN CITY ON COUNTRY.CODE = CITY.COUNTRYCODE 7 | WHERE COUNTRY.CONTINENT = "ASIA" -------------------------------------------------------------------------------- /SQL/Basic Join/The Report.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | */ 4 | SELECT CASE 5 | WHEN GRADES.GRADE > 7 THEN STUDENTS.NAME 6 | ELSE NULL 7 | END AS NAMES, 8 | GRADES.GRADE, 9 | STUDENTS.MARKS 10 | FROM STUDENTS 11 | JOIN GRADES 12 | ON STUDENTS.MARKS 13 | BETWEEN GRADES.MIN_MARK AND GRADES.MAX_MARK 14 | ORDER BY GRADES.GRADE DESC, 15 | NAMES ASC, 16 | STUDENTS.MARKS ASC; 17 | 18 | /* 19 | Britney 10 95 20 | Heraldo 10 94 21 | Julia 10 96 22 | Kristeen 10 100 23 | Stuart 10 99 24 | Amina 9 89 25 | Christene 9 88 26 | Salma 9 81 27 | Samantha 9 87 28 | Scarlet 9 80 29 | Vivek 9 84 30 | Aamina 8 77 31 | Belvet 8 78 32 | Paige 8 74 33 | Priya 8 76 34 | Priyanka 8 77 35 | NULL 7 64 36 | NULL 7 66 37 | NULL 6 55 38 | NULL 4 34 39 | NULL 3 24 40 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/EmployeeNames.sql: -------------------------------------------------------------------------------- 1 | SELECT name 2 | FROM Employee 3 | ORDER BY name; -------------------------------------------------------------------------------- /SQL/Basic Select/EmployeeSalaries.sql: -------------------------------------------------------------------------------- 1 | SELECT name 2 | FROM Employee 3 | WHERE salary > 2000 AND months < 10 4 | ORDER BY employee_id; -------------------------------------------------------------------------------- /SQL/Basic Select/HigherThan75Marks.sql: -------------------------------------------------------------------------------- 1 | SELECT Name 2 | FROM STUDENTS 3 | WHERE Marks > 75 4 | ORDER BY RIGHT(Name,3), ID; -------------------------------------------------------------------------------- /SQL/Basic Select/JapaneseCitiesAttributes.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query all attributes of every Japanese city in the CITY table. The COUNTRYCODE for Japan is JPN. 5 | */ 6 | 7 | SELECT * 8 | FROM CITY 9 | WHERE COUNTRYCODE = "JPN" 10 | 11 | /* 12 | 1613 Neyagawa JPN Osaka 257315 13 | 1630 Ageo JPN Saitama 209442 14 | 1661 Sayama JPN Saitama 162472 15 | 1681 Omuta JPN Fukuoka 142889 16 | 1739 Tokuyama JPN Yamaguchi 107078 17 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/JapaneseCitiesNames.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN. 5 | */ 6 | 7 | SELECT NAME 8 | FROM CITY 9 | WHERE COUNTRYCODE = "JPN" 10 | 11 | /* 12 | Neyagawa 13 | Ageo 14 | Sayama 15 | Omuta 16 | Tokuyama 17 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/RevisingtheSelectQuery1.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query all columns for all American cities in the CITY table with populations larger than 100000. The CountryCode for America is USA. 5 | */ 6 | 7 | SELECT * 8 | FROM CITY 9 | WHERE POPULATION > 100000 AND COUNTRYCODE = "USA" 10 | 11 | /* 12 | 3878 Scottsdale USA Arizona 202705 13 | 3965 Corona USA California 124966 14 | 3973 Concord USA California 121780 15 | 3977 Cedar Rapids USA Iowa 120758 16 | 3982 Coral Springs USA Florida 117549 17 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/RevisingtheSelectQuery2.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the NAME field for all American cities in the CITY table with populations larger than 120000. The CountryCode for America is USA. 5 | */ 6 | 7 | SELECT NAME 8 | FROM CITY 9 | WHERE POPULATION > 120000 AND COUNTRYCODE = "USA" 10 | 11 | /* 12 | Scottsdale 13 | Corona 14 | Concord 15 | Cedar Rapids 16 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation1.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | Query a list of CITY and STATE from the STATION table. 4 | The STATION table is described as follows: 5 | where LAT_N is the northern latitude and LONG_W is the western longitude. 6 | */ 7 | 8 | SELECT CITY,STATE 9 | FROM STATION 10 | 11 | /* 12 | Acme LA 13 | Addison MI 14 | Agency MO 15 | Aguanga CA 16 | Alanson MI 17 | Alba MI 18 | Albany CA 19 | Albion IN 20 | Algonac MI 21 | Aliso Viejo CA 22 | Allerton IA 23 | Alpine AR 24 | Alton MO 25 | Amazonia MO 26 | Amo IN 27 | Andersonville GA 28 | Andover CT 29 | Anthony KS 30 | Archie MO 31 | Arispe IA {-truncated-} 32 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation10.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the list of CITY names from STATION that do not end with vowels. Your result cannot contain duplicates. 5 | */ 6 | 7 | SELECT DISTINCT CITY 8 | FROM STATION 9 | WHERE NOT REGEXP_LIKE(CITY,'^.*[aeiouAEIOU]$'); 10 | 11 | /* 12 | Addison 13 | Agency 14 | Alanson 15 | Albany 16 | Albion 17 | Algonac 18 | Allerton 19 | Alton 20 | Andover 21 | Anthony 22 | Arlington 23 | Arrowsmith 24 | Athens 25 | Auburn 26 | Baker 27 | Baldwin 28 | Bass Harbor 29 | Beaufort 30 | Beaver Island 31 | Benedict {-truncated-} 32 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation11.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query the list of CITY names from STATION that either do not start with vowels or do not end with vowels. Your result cannot contain duplicates. 5 | */ 6 | 7 | SELECT DISTINCT CITY 8 | FROM STATION 9 | WHERE NOT REGEXP_LIKE(CITY,'^[aeiouAEIOU].*[aeiouAEIOU]$'); 10 | 11 | /* 12 | Addison 13 | Agency 14 | Alanson 15 | Albany 16 | Albion 17 | Algonac 18 | Allerton 19 | Alton 20 | Andover 21 | Anthony 22 | Arlington 23 | Arrowsmith 24 | Athens 25 | Auburn 26 | Baileyville 27 | Bainbridge 28 | Baker 29 | Baldwin 30 | Barrigada 31 | Bass Harbor {-truncated-} 32 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation12.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | Query the list of CITY names from STATION that do not start with vowels and do not end with vowels. Your result cannot contain duplicates. 4 | */ 5 | SELECT DISTINCT CITY 6 | FROM STATION 7 | WHERE NOT REGEXP_LIKE(CITY,'^[aeiouAEIOU]') AND NOT REGEXP_LIKE(CITY,'^.*[aeiouAEIOU]$'); 8 | 9 | /* 10 | Baker 11 | Baldwin 12 | Bass Harbor 13 | Beaufort 14 | Beaver Island 15 | Benedict 16 | Bennington 17 | Berryton 18 | Beverly 19 | Bison 20 | Blue River 21 | Bowdon 22 | Bowdon Junction 23 | Bridgeport 24 | Bridgton 25 | Brighton 26 | Brilliant 27 | Bristol 28 | Brownstown 29 | Buffalo Creek {-truncated-} 30 | */ 31 | 32 | -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation3.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer. 5 | */ 6 | 7 | SELECT DISTINCT CITY 8 | FROM STATION 9 | WHERE ID % 2 = 0; 10 | 11 | /* 12 | Aguanga 13 | Alba 14 | Albany 15 | Amo 16 | Andersonville 17 | Archie 18 | Athens 19 | Atlantic Mine 20 | Bainbridge 21 | Baker 22 | Bass Harbor 23 | Bayville 24 | Beaufort 25 | Bellevue 26 | Benedict 27 | Bennington 28 | Bentonville 29 | Biggsville 30 | Bison 31 | Bono {-truncated-} 32 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation4.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | 4 | Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table. 5 | */ 6 | 7 | SELECT COUNT(CITY) - COUNT(DISTINCT CITY) 8 | FROM STATION; 9 | 10 | /* 11 | 13 12 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation5.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | Query the two cities in STATION with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically. 4 | */ 5 | 6 | SELECT CITY, LENGTH(CITY) 7 | FROM STATION 8 | ORDER BY LENGTH(CITY) DESC, CITY 9 | LIMIT 1; 10 | 11 | SELECT CITY, LENGTH(CITY) 12 | FROM STATION 13 | ORDER BY LENGTH(CITY) ASC, CITY 14 | LIMIT 1; 15 | 16 | /* 17 | Amo 3 18 | Marine On Saint Croix 21 19 | */ -------------------------------------------------------------------------------- /SQL/Basic Select/WeatherObservationStation8.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Author: Eda AYDIN 3 | Query the list of CITY names from STATION which have vowels (i.e., a, e, i, o, and u) as both their first and last characters. Your result cannot contain duplicates. 4 | */ 5 | 6 | SELECT DISTINCT CITY 7 | FROM STATION 8 | WHERE REGEXP_LIKE(CITY,'^[aeiouAEIOU].*[aeiouAEIOU]$'); 9 | 10 | /* 11 | Upperco 12 | Aguanga 13 | East China 14 | East Irvine 15 | Amo 16 | Eleele 17 | Oconee 18 | Amazonia 19 | Aliso Viejo 20 | Andersonville 21 | Arkadelphia 22 | Eriline 23 | Eastlake 24 | Arispe 25 | Ermine 26 | Eufaula 27 | Osborne 28 | Elm Grove 29 | Atlantic Mine 30 | Oshtemo 31 | Archie 32 | Alpine 33 | Ojai 34 | Urbana 35 | Alba 36 | Eskridge 37 | Ozona 38 | Acme 39 | */ -------------------------------------------------------------------------------- /Skills Certification Test/Java (Basic)/The Adder Class/Solution.java: -------------------------------------------------------------------------------- 1 | import java.util.Scanner; 2 | 3 | abstract class Calculator { 4 | abstract int add(int a, int b); 5 | } 6 | 7 | /* 8 | Write the Adder class here. Do not use an access modifier at the beginning of your class declaration. 9 | */ 10 | class Adder extends Calculator{ 11 | int add(int a, int b){ 12 | return a + b; 13 | } 14 | } 15 | 16 | public class Solution { 17 | public static void main(String[] args) { 18 | int a, b; 19 | try (Scanner scan = new Scanner(System.in)) { 20 | a = scan.nextInt(); 21 | b = scan.nextInt(); 22 | } 23 | 24 | Calculator adderObject = new Adder(); 25 | System.out.println("The sum is: " + adderObject.add(a, b)); 26 | } 27 | } -------------------------------------------------------------------------------- /Skills Certification Test/SQL (Advanced)/count_the_employess.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Enter your query below. 3 | Please append a semicolon ";" at the end of the query 4 | 5 | The data for the number employed at several famous IT companies is maintained in the COMPANY table. 6 | Write a query to print the IDs of the companies that have more than 10000 employees, in ascending order of ID. 7 | */ 8 | 9 | SELECT ID 10 | FROM COMPANY 11 | WHERE EMPLOYEES > 10000 12 | ORDER BY ID ASC; -------------------------------------------------------------------------------- /Skills Certification Test/Software Engineer Intern/YoungestEmployees.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Enter your query here. 3 | 4 | There are two tables with employee information: EMPLOYEE and EMPLOYEE_UIN. Query the tables to generate a list of all employees who are less than 25 years old first in order of NAME, then of ID, both in ascending order. The result should include the UIN followed by the NAME. 5 | 6 | */ 7 | 8 | SELECT EMPLOYEE_UIN.UIN, EMPLOYEE.NAME 9 | FROM EMPLOYEE 10 | JOIN EMPLOYEE_UIN 11 | ON EMPLOYEE.ID = EMPLOYEE_UIN.ID 12 | WHERE EMPLOYEE.AGE < 25 13 | ORDER BY EMPLOYEE.NAME, EMPLOYEE.ID; 14 | -------------------------------------------------------------------------------- /Skills Certification/Java (Basic).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/Java (Basic).png -------------------------------------------------------------------------------- /Skills Certification/Problem Solving (Basic).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/Problem Solving (Basic).png -------------------------------------------------------------------------------- /Skills Certification/Problem Solving (Intermediate).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/Problem Solving (Intermediate).png -------------------------------------------------------------------------------- /Skills Certification/Python (Basic) Certificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/Python (Basic) Certificate.png -------------------------------------------------------------------------------- /Skills Certification/R (Intermediate).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/R (Intermediate).png -------------------------------------------------------------------------------- /Skills Certification/SQL (Advanced).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/SQL (Advanced).png -------------------------------------------------------------------------------- /Skills Certification/SQL (Basic) Certificate.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/SQL (Basic) Certificate.png -------------------------------------------------------------------------------- /Skills Certification/SQL (Intermediate).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/SQL (Intermediate).png -------------------------------------------------------------------------------- /Skills Certification/Software Engineer Intern.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/Software Engineer Intern.png -------------------------------------------------------------------------------- /Skills Certification/Software Engineer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/edaaydinea/HackerRank/ce904a86a7b97c33056d79f4ba45c62a7c57faa5/Skills Certification/Software Engineer.png -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/01 - Warm-up Challenges/Repeated String.py: -------------------------------------------------------------------------------- 1 | """ 2 | Problem: https://www.hackerrank.com/challenges/repeated-string/problem 3 | 4 | Author: Eda AYDIN 5 | """ 6 | # !/bin/python3 7 | 8 | import math 9 | import os 10 | import random 11 | import re 12 | import sys 13 | 14 | 15 | # 16 | # Complete the 'repeatedString' function below. 17 | # 18 | # The function is expected to return a LONG_INTEGER. 19 | # The function accepts following parameters: 20 | # 1. STRING s 21 | # 2. LONG_INTEGER n 22 | # 23 | 24 | def repeatedString(s, n): 25 | # Write your code here 26 | new_string_count = n // len(s) * s.count("a") 27 | remained_string_count = s[:(n % len(s))].count("a") 28 | return new_string_count + remained_string_count 29 | 30 | 31 | if __name__ == '__main__': 32 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 33 | s = input() 34 | n = int(input().strip()) 35 | result = repeatedString(s, n) 36 | fptr.write(str(result) + '\n') 37 | fptr.close() 38 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/02 - Arrays/Arrays - Left Rotation.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'rotLeft' function below. 11 | # 12 | # The function is expected to return an INTEGER_ARRAY. 13 | # The function accepts following parameters: 14 | # 1. INTEGER_ARRAY a 15 | # 2. INTEGER d 16 | # 17 | 18 | def rotLeft(a, d): 19 | # Write your code here 20 | size = len(a) 21 | 22 | if size < d: 23 | d = size % d 24 | return a[d:size] + a[0:d] 25 | 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | first_multiple_input = input().rstrip().split() 31 | 32 | n = int(first_multiple_input[0]) 33 | 34 | d = int(first_multiple_input[1]) 35 | 36 | a = list(map(int, input().rstrip().split())) 37 | 38 | result = rotLeft(a, d) 39 | 40 | fptr.write(' '.join(map(str, result))) 41 | fptr.write('\n') 42 | 43 | fptr.close() 44 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/02 - Arrays/Minimum Swaps 2.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the minimumSwaps function below. 10 | def minimumSwaps(arr): 11 | total_swaps = 0 12 | start = 0 13 | 14 | while start < len(arr): 15 | if arr[start] == start + 1: 16 | start +=1 17 | continue 18 | arr[arr[start] - 1], arr[start] = arr[start], arr[arr[start]-1] 19 | total_swaps +=1 20 | return total_swaps 21 | 22 | 23 | if __name__ == '__main__': 24 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 25 | 26 | n = int(input()) 27 | 28 | arr = list(map(int, input().rstrip().split())) 29 | 30 | res = minimumSwaps(arr) 31 | 32 | fptr.write(str(res) + '\n') 33 | 34 | fptr.close() 35 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/02 - Arrays/New Year Chaos.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'minimumBribes' function below. 12 | # 13 | # The function accepts INTEGER_ARRAY q as parameter. 14 | # 15 | 16 | def minimumBribes(q): 17 | # Write your code here 18 | bribes = 0 19 | 20 | for i in range(len(q) - 1, -1, -1): 21 | if q[i] - (i + 1) > 2: 22 | print("Too chaotic") 23 | return 24 | for j in range(max(0, q[i] - 2), i): 25 | if q[j] > q[i]: 26 | bribes += 1 27 | print(bribes) 28 | 29 | 30 | if __name__ == '__main__': 31 | t = int(input().strip()) 32 | 33 | for t_itr in range(t): 34 | n = int(input().strip()) 35 | 36 | q = list(map(int, input().rstrip().split())) 37 | 38 | minimumBribes(q) 39 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/03 - Dictionaries and Hashmaps/Count Triplets.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | from collections import defaultdict 9 | 10 | 11 | # Complete the countTriplets function below. 12 | def countTriplets(arr, r): 13 | arr2 = defaultdict(int) 14 | arr3 = defaultdict(int) 15 | count = 0 16 | 17 | for i in arr: 18 | count += arr3[i] 19 | arr3[i * r] += arr2[i] 20 | arr2[i * r] += 1 21 | return count 22 | 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | 27 | nr = input().rstrip().split() 28 | 29 | n = int(nr[0]) 30 | 31 | r = int(nr[1]) 32 | 33 | arr = list(map(int, input().rstrip().split())) 34 | 35 | ans = countTriplets(arr, r) 36 | 37 | fptr.write(str(ans) + '\n') 38 | 39 | fptr.close() 40 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/03 - Dictionaries and Hashmaps/Two Strings.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'twoStrings' function below. 11 | # 12 | # The function is expected to return a STRING. 13 | # The function accepts following parameters: 14 | # 1. STRING s1 15 | # 2. STRING s2 16 | # 17 | 18 | def twoStrings(s1, s2): 19 | # Write your code here 20 | for i in s1: 21 | if i in s2: 22 | return "YES" 23 | return "No" 24 | 25 | if __name__ == '__main__': 26 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 27 | q = int(input().strip()) 28 | 29 | for q_itr in range(q): 30 | s1 = input() 31 | s2 = input() 32 | result = twoStrings(s1, s2) 33 | fptr.write(result + '\n') 34 | 35 | fptr.close() 36 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/04 - Sorting/Sorting - Bubble Sort.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | 4 | # 5 | # Complete the 'countSwaps' function below. 6 | # 7 | # The function accepts INTEGER_ARRAY a as parameter. 8 | # 9 | 10 | def countSwaps(a): 11 | # Write your code here 12 | count = 0 13 | size = len(a) 14 | 15 | for i in range(size): 16 | for j in range(i + 1, size): 17 | if a[j] < a[i]: 18 | a[i] = a[i] + a[j] 19 | a[j] = a[i] - a[j] 20 | a[i] = a[i] - a[j] 21 | count += 1 22 | 23 | print("Array is sorted in {} swaps.".format(count)) 24 | print("First Element: {}".format(a[0])) 25 | print("Last Element: {}".format(a[-1])) 26 | 27 | 28 | if __name__ == '__main__': 29 | n = int(input().strip()) 30 | 31 | a = list(map(int, input().rstrip().split())) 32 | 33 | countSwaps(a) 34 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/04 - Sorting/Sorting - Comparator.py: -------------------------------------------------------------------------------- 1 | from functools import cmp_to_key 2 | 3 | 4 | class Player: 5 | def __init__(self, name, score): 6 | self.name = name 7 | self.score = score 8 | 9 | def __repr__(self): 10 | pass 11 | 12 | def comparator(a, b): 13 | if a.score < b.score: 14 | return 1 15 | elif a.score > b.score: 16 | return -1 17 | else: 18 | if a.name > b.name: 19 | return 1 20 | elif a.name < b.name: 21 | return -1 22 | else: 23 | return 0 24 | 25 | 26 | n = int(input()) 27 | data = [] 28 | 29 | for i in range(n): 30 | name, score = input().split() 31 | score = int(score) 32 | player = Player(name, score) 33 | data.append(player) 34 | 35 | data = sorted(data, key=cmp_to_key(Player.comparator)) 36 | for i in data: 37 | print(i.name, i.score) 38 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/05 - String Manipulation/Alternating Characters.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'alternatingCharacters' function below. 8 | # 9 | # The function is expected to return an INTEGER. 10 | # The function accepts STRING s as parameter. 11 | # 12 | 13 | def alternatingCharacters(s): 14 | # Write your code here 15 | deletions = 0 16 | 17 | for i in range(1, len(s)): 18 | if s[i] == s[i - 1]: 19 | deletions += 1 20 | 21 | return deletions 22 | 23 | 24 | if __name__ == '__main__': 25 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 26 | q = int(input().strip()) 27 | for q_itr in range(q): 28 | s = input() 29 | result = alternatingCharacters(s) 30 | fptr.write(str(result) + '\n') 31 | fptr.close() 32 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/05 - String Manipulation/Common Child.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'commonChild' function below. 8 | # 9 | # The function is expected to return an INTEGER. 10 | # The function accepts following parameters: 11 | # 1. STRING s1 12 | # 2. STRING s2 13 | # 14 | 15 | def commonChild(s1, s2): 16 | last_row = [0] * (len(s1) + 1) 17 | 18 | for i in range(1, len(s1) + 1): 19 | current = [0] 20 | for j in range(1, len(s2) + 1): 21 | if s1[i - 1] == s2[j - 1]: 22 | current.append(last_row[j - 1] + 1) 23 | else: 24 | current.append(max(last_row[j], current[-1])) 25 | last_row = current 26 | 27 | return last_row[-1] 28 | 29 | 30 | if __name__ == '__main__': 31 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 32 | 33 | s1 = input() 34 | 35 | s2 = input() 36 | 37 | result = commonChild(s1, s2) 38 | 39 | fptr.write(str(result) + '\n') 40 | 41 | fptr.close() 42 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/05 - String Manipulation/Special String Again.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # Complete the substrCount function below. 11 | def substrCount(n, s): 12 | palindrome_count = 0 13 | 14 | for i in range(n): 15 | j = 0 16 | 17 | while i + j < n and s[i] == s[i + j]: 18 | j += 1 19 | palindrome_count += 1 20 | 21 | if i + j + j > n: 22 | continue 23 | 24 | for k in range(1, j + 1): 25 | if i + j + k >= n or s[i] != s[i + j + k]: 26 | break 27 | else: 28 | palindrome_count += 1 29 | 30 | return palindrome_count 31 | 32 | 33 | if __name__ == '__main__': 34 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 35 | 36 | n = int(input()) 37 | 38 | s = input() 39 | 40 | result = substrCount(n, s) 41 | 42 | fptr.write(str(result) + '\n') 43 | 44 | fptr.close() 45 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/05 - String Manipulation/Strings- Making Anagrams.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | # 6 | # Complete the 'makeAnagram' function below. 7 | # 8 | # The function is expected to return an INTEGER. 9 | # The function accepts following parameters: 10 | # 1. STRING a 11 | # 2. STRING b 12 | # 13 | from collections import Counter 14 | 15 | 16 | def makeAnagram(a, b): 17 | # Write your code here 18 | count_a = Counter(a) 19 | count_b = Counter(b) 20 | 21 | difference_a = count_a - count_b 22 | difference_b = count_b - count_a 23 | 24 | return sum(difference_a.values()) + sum(difference_b.values()) 25 | 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | a = input() 30 | b = input() 31 | res = makeAnagram(a, b) 32 | fptr.write(str(res) + '\n') 33 | fptr.close() 34 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/06 - Greedy Algorithms/Greedy Florist.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # Complete the getMinimumCost function below. 11 | def getMinimumCost(k, c): 12 | sorted_c = sorted(c, reverse=True) 13 | s = 0 14 | counter = 0 15 | additional = 0 16 | 17 | for c in sorted_c: 18 | if counter == k: 19 | counter = 0 20 | additional += 1 21 | 22 | s += (additional + 1) * c 23 | counter += 1 24 | 25 | return s 26 | 27 | 28 | if __name__ == '__main__': 29 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 30 | 31 | nk = input().split() 32 | 33 | n = int(nk[0]) 34 | 35 | k = int(nk[1]) 36 | 37 | c = list(map(int, input().rstrip().split())) 38 | 39 | minimumCost = getMinimumCost(k, c) 40 | 41 | fptr.write(str(minimumCost) + '\n') 42 | 43 | fptr.close() 44 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/06 - Greedy Algorithms/Minimum Absolute Difference in an Array.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'minimumAbsoluteDifference' function below. 12 | # 13 | # The function is expected to return an INTEGER. 14 | # The function accepts INTEGER_ARRAY arr as parameter. 15 | # 16 | 17 | def minimumAbsoluteDifference(array): 18 | # Write your code here 19 | array.sort() 20 | diff = abs(array[0] - array[1]) 21 | for i in range(1, len(array)-1): 22 | if abs(array[i] - array[i + 1]) < diff: 23 | diff = abs(array[i] - array[i + 1]) 24 | return diff 25 | 26 | 27 | if __name__ == '__main__': 28 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 29 | 30 | n = int(input().strip()) 31 | 32 | arr = list(map(int, input().rstrip().split())) 33 | 34 | result = minimumAbsoluteDifference(arr) 35 | 36 | fptr.write(str(result) + '\n') 37 | 38 | fptr.close() 39 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/07 - Search/Hash Tables - Ice Cream Parlor.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'whatFlavors' function below. 12 | # 13 | # The function accepts following parameters: 14 | # 1. INTEGER_ARRAY cost 15 | # 2. INTEGER money 16 | # 17 | 18 | def whatFlavors(cost, money): 19 | # Write your code here 20 | dictionary = {} 21 | 22 | for id, price in enumerate(cost): 23 | if money - price in dictionary.keys(): 24 | print("{} {}".format(dictionary[money - price] + 1, id + 1)) 25 | dictionary[price] = id 26 | return None 27 | 28 | 29 | if __name__ == '__main__': 30 | t = int(input().strip()) 31 | 32 | for t_itr in range(t): 33 | money = int(input().strip()) 34 | 35 | n = int(input().strip()) 36 | 37 | cost = list(map(int, input().rstrip().split())) 38 | 39 | whatFlavors(cost, money) 40 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/08 - Dynamic Programming/Max Array Sum.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # Complete the maxSubsetSum function below. 10 | def maxSubsetSum(arr): 11 | dp = [0] * len(arr) 12 | dp[0], dp[1] = arr[0], max(arr[0],arr[1]) 13 | 14 | for i in range(2,n): 15 | dp[i] = max(dp[i - 1], dp[i - 2] + arr[i], arr[i]) 16 | 17 | return dp[-1] 18 | 19 | if __name__ == '__main__': 20 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 21 | 22 | n = int(input()) 23 | 24 | arr = list(map(int, input().rstrip().split())) 25 | 26 | res = maxSubsetSum(arr) 27 | 28 | fptr.write(str(res) + '\n') 29 | 30 | fptr.close() 31 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/11 - Trees/Trees - Is this a Binary Search Tree.py: -------------------------------------------------------------------------------- 1 | """ Node is defined as 2 | class node: 3 | def __init__(self, data): 4 | self.data = data 5 | self.left = None 6 | self.right = None 7 | """ 8 | 9 | def checkBST(root): 10 | return isBST(root, -1, 10001) 11 | 12 | def isBST(root, left, right): 13 | if root is None: 14 | return True 15 | if root.data <= left or root.data>= right: 16 | return False 17 | return (isBST(root.left, left, root.data) and isBST(root.right, root.data, right)) -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/12 - Linked Lists/Linked Lists - Detect a cycle.py: -------------------------------------------------------------------------------- 1 | """ 2 | Detect a cycle in a linked list. Note that the head pointer may be 'None' if the list is empty. 3 | 4 | A Node is defined as: 5 | 6 | class Node(object): 7 | def __init__(self, data = None, next_node = None): 8 | self.data = data 9 | self.next = next_node 10 | """ 11 | 12 | 13 | def has_cycle(head): 14 | if head is None: 15 | return False 16 | 17 | slow = head 18 | fast = head.next 19 | 20 | while slow != fast: 21 | if fast is None or fast.next is None: 22 | return False 23 | slow = slow.next 24 | fast = fast.next.next 25 | 26 | return True -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/13 - Recursion and Backtracking/Recursion - Davis Staircase.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import os 4 | 5 | 6 | # 7 | # Complete the 'stepPerms' function below. 8 | # 9 | # The function is expected to return an INTEGER. 10 | # The function accepts INTEGER n as parameter. 11 | # 12 | 13 | def stepPerms(number): 14 | # Write your code here 15 | ds = [0] * max(3, number + 1) 16 | ds[0] = 1 17 | ds[1] = 1 18 | ds[2] = ds[1] + ds[0] 19 | 20 | for i in range(3, number + 1): 21 | ds[i] = (ds[i - 1] + ds[i - 2] + ds[i - 3]) % 10000000007 22 | 23 | return ds[number] 24 | 25 | 26 | if __name__ == '__main__': 27 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 28 | 29 | s = int(input().strip()) 30 | 31 | for s_itr in range(s): 32 | n = int(input().strip()) 33 | 34 | res = stepPerms(n) 35 | 36 | fptr.write(str(res) + '\n') 37 | 38 | fptr.close() 39 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/13 - Recursion and Backtracking/Recursion - Fibonacci Numbers.py: -------------------------------------------------------------------------------- 1 | def fibonacci(number): 2 | # Write your code here. 3 | if number == 0: 4 | return 0 5 | if number == 1: 6 | return 1 7 | 8 | return fibonacci(number - 1) + fibonacci(number - 2) 9 | 10 | 11 | if __name__ == "__main__": 12 | n = int(input()) 13 | print(fibonacci(n)) 14 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/13 - Recursion and Backtracking/Recursive Digit Sum.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import sys 4 | sys.setrecursionlimit(1000000) 5 | 6 | 7 | # 8 | # Complete the 'superDigit' function below. 9 | # 10 | # The function is expected to return an INTEGER. 11 | # The function accepts following parameters: 12 | # 1. STRING n 13 | # 2. INTEGER k 14 | # 15 | 16 | def superDigit(number): 17 | # Write your code here 18 | while number > 9: 19 | number = sum(map(int, str(number))) 20 | return number 21 | 22 | 23 | if __name__ == '__main__': 24 | n, k = map(int, input().split()) 25 | print(superDigit(superDigit(n) * k)) -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/14 - Miscellaneous/Flipping bits.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | # 10 | # Complete the 'flippingBits' function below. 11 | # 12 | # The function is expected to return a LONG_INTEGER. 13 | # The function accepts LONG_INTEGER n as parameter. 14 | # 15 | 16 | def flippingBits(n): 17 | # Write your code here 18 | result = 0 19 | k = 1 20 | 21 | for _ in range(32): 22 | if n & 1 == 0: 23 | result += k 24 | 25 | k <<= 1 26 | n >>= 1 27 | 28 | return result 29 | 30 | if __name__ == '__main__': 31 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 32 | 33 | q = int(input().strip()) 34 | 35 | for q_itr in range(q): 36 | n = int(input().strip()) 37 | 38 | result = flippingBits(n) 39 | 40 | fptr.write(str(result) + '\n') 41 | 42 | fptr.close() 43 | -------------------------------------------------------------------------------- /The HackerRank Interview Preparation Kit/14 - Miscellaneous/Time Complexity - Primality.py: -------------------------------------------------------------------------------- 1 | #!/bin/python3 2 | 3 | import math 4 | import os 5 | import random 6 | import re 7 | import sys 8 | 9 | 10 | # 11 | # Complete the 'primality' function below. 12 | # 13 | # The function is expected to return a STRING. 14 | # The function accepts INTEGER n as parameter. 15 | # 16 | 17 | 18 | def primality(n): 19 | # Write your code here 20 | if n == 1: 21 | return "Not prime" 22 | if n == 2: 23 | return "Prime" 24 | 25 | i = 2 26 | while i <= math.sqrt(n): 27 | if n % i == 0: 28 | return "Not prime" 29 | i += 1 30 | 31 | return "Prime" 32 | 33 | 34 | if __name__ == '__main__': 35 | fptr = open(os.environ['OUTPUT_PATH'], 'w') 36 | 37 | p = int(input().strip()) 38 | 39 | for p_itr in range(p): 40 | n = int(input().strip()) 41 | 42 | result = primality(n) 43 | 44 | fptr.write(result + '\n') 45 | 46 | fptr.close() 47 | --------------------------------------------------------------------------------