├── .gitignore
├── .idea
├── .gitignore
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── compiler.xml
├── jarRepositories.xml
├── misc.xml
└── vcs.xml
├── HackerRank1
├── Cracking the Coding Interview
│ ├── Algorithms
│ │ ├── BFS Shortest Reach in a Graph
│ │ │ └── Solution.java
│ │ ├── DFS Connected Cell in a Grid
│ │ │ └── Solution.java
│ │ ├── Hash Tables Ice Cream Parlor
│ │ │ └── Solution.java
│ │ ├── Merge Sort Counting Inversions
│ │ │ └── Solution.java
│ │ ├── Sorting Bubble Sort
│ │ │ └── Solution.java
│ │ └── Sorting Comparator
│ │ │ └── Solution.java
│ ├── Data Structures
│ │ ├── Arrays Left Rotation
│ │ │ └── Solution.java
│ │ ├── Hash Tables Ransom Note
│ │ │ └── Solution.java
│ │ ├── Heaps Find the Running Median
│ │ │ └── Solution.java
│ │ ├── Linked Lists Detect a Cycle
│ │ │ └── Solution.java
│ │ ├── Queues A Tale of Two Stacks
│ │ │ └── Solution.java
│ │ ├── Stacks Balanced Brackets
│ │ │ └── Solution.java
│ │ ├── Strings Making Anagrams
│ │ │ └── Solution.java
│ │ ├── Trees Is This a Binary Search Tree
│ │ │ └── Solution.java
│ │ └── Tries Contacts
│ │ │ └── Solution.java
│ ├── README.md
│ └── Techniques Concepts
│ │ ├── Bit Manipulation Lonely Integer
│ │ └── Solution.java
│ │ ├── DP Coin Change
│ │ └── Solution.java
│ │ ├── Recursion Davis' Staircase
│ │ └── Solution.java
│ │ ├── Recursion Fibonacci Numbers
│ │ └── Solution.java
│ │ └── Time Complexity Primality
│ │ └── Solution.java
├── Functional Programming
│ ├── Introduction
│ │ ├── Array Of N Elements
│ │ │ └── Solution.scala
│ │ ├── Filter Array
│ │ │ └── Solution.scala
│ │ ├── Filter Positions in a List
│ │ │ └── Solution.scala
│ │ ├── Hello World N Times
│ │ │ └── Solution.scala
│ │ ├── Hello World
│ │ │ └── Solution.scala
│ │ ├── Lambda Calculus - Reductions #1
│ │ │ └── Solution.txt
│ │ ├── Lambda Calculus - Reductions #2
│ │ │ └── Solution.txt
│ │ ├── List Length
│ │ │ └── Solution.scala
│ │ ├── List Replication
│ │ │ └── Solution.scala
│ │ ├── Reverse a List
│ │ │ └── Solution.scala
│ │ ├── Solve Me First FP
│ │ │ └── Solution.scala
│ │ ├── Sum of Odd Elements
│ │ │ └── Solution.scala
│ │ └── Update List
│ │ │ └── Solution.scala
│ └── README.md
├── Interview Preparation Kit
│ ├── Arrays
│ │ ├── 2D Array - DS
│ │ │ └── Solution.java
│ │ ├── Arrays Left Rotation
│ │ │ └── Solution.java
│ │ ├── Minimum Swaps 2
│ │ │ └── Solution.java
│ │ └── New Year Chaos
│ │ │ └── New Year Chaos.cpp
│ ├── Dictionaries and Hashmaps
│ │ ├── Hash Tables Ransom Note
│ │ │ └── Solution.java
│ │ ├── Sherlock and Anagrams
│ │ │ └── Solution.java
│ │ └── Two Strings
│ │ │ └── Solution.java
│ ├── Dynamic Programming
│ │ ├── Candies
│ │ │ └── Solution.java
│ │ └── Max Array Sum
│ │ │ └── Solution.java
│ ├── Graphs
│ │ ├── BFS Shortest Reach in a Graph
│ │ │ └── Solution.java
│ │ └── DFS Connected Cell in a Grid
│ │ │ └── Solution.java
│ ├── Greedy Algorithms
│ │ ├── Greedy Florist
│ │ │ └── Solution.java
│ │ ├── Luck Balance
│ │ │ └── Solution.java
│ │ ├── Max Min
│ │ │ └── Solution.java
│ │ └── Minimum Absolute Difference in an Array
│ │ │ └── Solution.java
│ ├── Linked Lists
│ │ ├── Find Merge Point of Two Lists
│ │ │ └── Solution.java
│ │ ├── Linked Lists Detect a Cycle
│ │ │ └── Solution.java
│ │ └── Reverse a Doubly Linked List
│ │ │ └── Solution.java
│ ├── Miscellaneous
│ │ ├── Flipping bits
│ │ │ └── Solution.java
│ │ └── Time Complexity Primality
│ │ │ └── Solution.java
│ ├── README.md
│ ├── Recursion and Backtracking
│ │ ├── Recursion Davis' Staircase
│ │ │ └── Solution.java
│ │ └── Recursion Fibonacci Numbers
│ │ │ └── Solution.java
│ ├── Search
│ │ ├── Hash Tables Ice Cream Parlor
│ │ │ └── Solution.java
│ │ └── Pairs
│ │ │ └── Solution.java
│ ├── Sorting
│ │ ├── Mark and Toys
│ │ │ └── Solution.java
│ │ ├── Merge Sort Counting Inversions
│ │ │ └── Solution.java
│ │ ├── Sorting Bubble Sort
│ │ │ └── Solution.java
│ │ └── Sorting Comparator
│ │ │ └── Solution.java
│ ├── Stacks and Queues
│ │ ├── Balanced Brackets
│ │ │ └── Solution.java
│ │ └── Queues A Tale of Two Stacks
│ │ │ └── Solution.java
│ ├── String Manipulation
│ │ ├── Alternating Characters
│ │ │ └── Solution.java
│ │ └── Strings Making Anagrams
│ │ │ └── Solution.java
│ ├── Trees
│ │ ├── Binary Search Tree Lowest Common Ancestor
│ │ │ └── Solution.java
│ │ ├── Tree Height of a Binary Tree
│ │ │ └── Solution.java
│ │ └── Trees Is This a Binary Search Tree
│ │ │ └── Solution.java
│ └── Warm-up Challenges
│ │ ├── Counting Valleys
│ │ └── Solution.java
│ │ ├── Jumping on the Clouds
│ │ └── Solution.java
│ │ ├── Repeated String
│ │ └── Solution.java
│ │ └── Sock Merchant
│ │ └── Solution.java
├── Java
│ ├── Advanced
│ │ ├── Can You Access
│ │ │ └── Solution.java
│ │ ├── Covariant Return Types
│ │ │ └── Solution.java
│ │ ├── Java Annotations
│ │ │ └── Solution.java
│ │ ├── Java Factory Pattern
│ │ │ └── Solution.java
│ │ ├── Java Lambda Expressions
│ │ │ └── Solution.java
│ │ ├── Java MD5
│ │ │ └── Solution.java
│ │ ├── Java Reflection - Attributes
│ │ │ └── Solution.java
│ │ ├── Java SHA-256
│ │ │ └── Solution.java
│ │ ├── Java Singleton Pattern
│ │ │ └── Solution.java
│ │ ├── Java Varargs - Simple Addition
│ │ │ └── Solution.java
│ │ ├── Java Visitor Pattern
│ │ │ └── Solution.java
│ │ └── Prime Checker
│ │ │ └── Solution.java
│ ├── BigNumber
│ │ ├── Java BigDecimal
│ │ │ └── Solution.java
│ │ ├── Java BigInteger
│ │ │ └── Solution.java
│ │ └── Java Primality Test
│ │ │ └── Solution.java
│ ├── 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
│ ├── Exception Handling
│ │ ├── Java Exception Handling (Try-catch)
│ │ │ └── Solution.java
│ │ └── Java Exception Handling
│ │ │ └── Solution.java
│ ├── Introduction
│ │ ├── Java Currency Formatter
│ │ │ └── Solution.java
│ │ ├── Java Datatypes
│ │ │ └── Solution.java
│ │ ├── Java Date and Time
│ │ │ └── Solution.java
│ │ ├── Java End-of-file
│ │ │ └── Solution.java
│ │ ├── Java If-Else
│ │ │ └── Solution.java
│ │ ├── Java Int to String
│ │ │ └── Solution.java
│ │ ├── Java Loops 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
│ │ └── Welcome to Java!
│ │ │ └── Solution.java
│ ├── 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
│ ├── README.md
│ └── Strings
│ │ ├── Java Anagrams
│ │ └── Solution.java
│ │ ├── Java Regex 2 - Duplicate Words
│ │ └── Solution.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
├── LICENSE
├── Problem Solving
│ └── Algorithms
│ │ ├── Greedy Florist
│ │ └── Solution.java
│ │ ├── Greedy
│ │ ├── Luck Balance
│ │ │ └── Solution.java
│ │ ├── Mark and Toys
│ │ │ └── Solution.java
│ │ └── Minimum Absolute Difference in an Array
│ │ │ └── Solution.java
│ │ ├── Implementation
│ │ ├── Counting Valleys
│ │ │ └── Solution.java
│ │ ├── Jumping on the Clouds
│ │ │ └── Solution.java
│ │ ├── Repeated String
│ │ │ └── Solution.java
│ │ └── Sock Merchant
│ │ │ └── Solution.java
│ │ ├── Search
│ │ └── Pairs
│ │ │ └── Solution.java
│ │ └── Strings
│ │ ├── Alternating Characters
│ │ └── Solution.java
│ │ ├── Sherlock and Anagrams
│ │ └── Solution.java
│ │ └── Two Strings
│ │ └── Solution.java
├── Python
│ ├── Basic Data Types
│ │ ├── Find the Runner-Up Score!
│ │ │ └── Solution.py
│ │ ├── Finding the percentage
│ │ │ └── Solution.py
│ │ ├── List Comprehensions
│ │ │ └── Solution.py
│ │ ├── Lists
│ │ │ └── Solution.py
│ │ ├── Nested Lists
│ │ │ └── Solution.py
│ │ └── Tuples
│ │ │ └── Solution.py
│ ├── Built-Ins
│ │ ├── Any or All
│ │ │ └── Solution.py
│ │ ├── Athlete Sort
│ │ │ └── Solution.py
│ │ ├── Input()
│ │ │ └── Solution.py
│ │ ├── Python Evaluation
│ │ │ └── Solution.py
│ │ ├── Zipped!
│ │ │ └── Solution.py
│ │ └── ginortS
│ │ │ └── Solution.py
│ ├── Classes
│ │ ├── Class 2 - Find the Torsional Angle
│ │ │ └── Solution.py
│ │ └── Classes Dealing with Complex Numbers
│ │ │ └── Solution.py
│ ├── Closures and Decorators
│ │ ├── Decorators 2 - Name Directory
│ │ │ └── Solution.py
│ │ └── Standardize Mobile Number Using Decorators
│ │ │ └── Solution.py
│ ├── Collections
│ │ ├── Collections.Counter()
│ │ │ └── Solution.py
│ │ ├── Collections.OrderedDict()
│ │ │ └── Solution.py
│ │ ├── Collections.deque()
│ │ │ └── Solution.py
│ │ ├── Collections.namedtuple()
│ │ │ └── Solution.py
│ │ ├── Company Logo
│ │ │ └── Solution.py
│ │ ├── DefaultDict Tutorial
│ │ │ └── Solution.py
│ │ ├── Piling Up!
│ │ │ └── Solution.py
│ │ └── Word Order
│ │ │ └── Solution.py
│ ├── Date and Time
│ │ ├── Calendar Module
│ │ │ └── Solution.py
│ │ └── Time Delta
│ │ │ └── Solution.py
│ ├── Debugging
│ │ ├── Default Arguments
│ │ │ └── Solution.py
│ │ └── Words Score
│ │ │ └── Solution.py
│ ├── Errors and Exceptions
│ │ ├── Exceptions
│ │ │ └── Solution.py
│ │ └── Incorrect Regex
│ │ │ └── Solution.py
│ ├── Introduction
│ │ ├── Arithmetic Operators
│ │ │ └── Solution.py
│ │ ├── Loops
│ │ │ └── Solution.py
│ │ ├── Print Function
│ │ │ └── Solution.py
│ │ ├── Python Division
│ │ │ └── Solution.py
│ │ ├── Python If-Else
│ │ │ └── Solution.py
│ │ ├── Say Hello, World! With Python
│ │ │ └── Solution.py
│ │ └── Write a function
│ │ │ └── Solution.py
│ ├── Itertools
│ │ ├── Compress the String!
│ │ │ └── Solution.py
│ │ ├── Iterables and Iterators
│ │ │ └── Solution.py
│ │ ├── Maximize It!
│ │ │ └── Solution.py
│ │ ├── itertools.combinations()
│ │ │ └── Solution.py
│ │ ├── itertools.combinations_with_replacement()
│ │ │ └── Solution.py
│ │ ├── itertools.permutations()
│ │ │ └── Solution.py
│ │ └── itertools.product()
│ │ │ └── Solution.py
│ ├── Math
│ │ ├── Find Angle MBC
│ │ │ └── Solution.py
│ │ ├── Integers Come In All Sizes
│ │ │ └── Solution.py
│ │ ├── Mod Divmod
│ │ │ └── Solution.py
│ │ ├── Polar Coordinates
│ │ │ └── Solution.py
│ │ ├── Power - Mod Power
│ │ │ └── Solution.py
│ │ ├── Triangle Quest 2
│ │ │ └── Solution.py
│ │ └── Triangle Quest
│ │ │ └── Solution.py
│ ├── Numpy
│ │ ├── Array Mathematics
│ │ │ └── Solution.py
│ │ ├── Arrays
│ │ │ └── Solution.py
│ │ ├── Concatenate
│ │ │ └── Solution.py
│ │ ├── Dot and Cross
│ │ │ └── Solution.py
│ │ ├── Eye and Identity
│ │ │ └── Solution.py
│ │ ├── Floor, Ceil and Rint
│ │ │ └── Solution.py
│ │ ├── Inner and Outer
│ │ │ └── Solution.py
│ │ ├── Linear Algebra
│ │ │ └── Solution.py
│ │ ├── Mean, Var, and Std
│ │ │ └── Solution.py
│ │ ├── Min and Max
│ │ │ └── Solution.py
│ │ ├── Polynomials
│ │ │ └── Solution.py
│ │ ├── Shape and Reshape
│ │ │ └── Solution.py
│ │ ├── Sum and Prod
│ │ │ └── Solution.py
│ │ ├── Transpose and Flatten
│ │ │ └── Solution.py
│ │ └── Zeros and Ones
│ │ │ └── Solution.py
│ ├── Python Functionals
│ │ ├── Map and Lambda Function
│ │ │ └── Solution.py
│ │ ├── Reduce Function
│ │ │ └── Solution.py
│ │ └── Validating Email Addresses With a Filter
│ │ │ └── Solution.py
│ ├── README.md
│ ├── Regex and Parsing
│ │ ├── Detect Floating Point Number
│ │ │ └── Solution.py
│ │ ├── Detect HTML Tags, Attributes and Attribute Values
│ │ │ └── Solution.py
│ │ ├── Group(), Groups() & Groupdict()
│ │ │ └── Solution.py
│ │ ├── HTML Parser - Part 1
│ │ │ └── Solution.py
│ │ ├── HTML Parser - Part 2
│ │ │ └── Solution.py
│ │ ├── Hex Color Code
│ │ │ └── Solution.py
│ │ ├── Matrix Script
│ │ │ └── Solution.py
│ │ ├── Re.findall() & Re.finditer()
│ │ │ └── Solution.py
│ │ ├── Re.split()
│ │ │ └── Solution.py
│ │ ├── Re.start() & Re.end()
│ │ │ └── Solution.py
│ │ ├── Regex Substitution
│ │ │ └── Solution.py
│ │ ├── Validating Credit Card Numbers
│ │ │ └── Solution.py
│ │ ├── Validating Postal Codes
│ │ │ └── Solution.py
│ │ ├── Validating Roman Numerals
│ │ │ └── Solution.py
│ │ ├── Validating UID
│ │ │ └── Solution.py
│ │ ├── Validating and Parsing Email Addresses
│ │ │ └── Solution.py
│ │ └── Validating phone numbers
│ │ │ └── Solution.py
│ ├── Sets
│ │ ├── Check Strict Superset
│ │ │ └── Solution.py
│ │ ├── Check Subset
│ │ │ └── Solution.py
│ │ ├── Introduction to Sets
│ │ │ └── Solution.py
│ │ ├── No Idea!
│ │ │ └── Solution.py
│ │ ├── Set .add()
│ │ │ └── Solution.py
│ │ ├── Set .difference() Operation
│ │ │ └── Solution.py
│ │ ├── Set .discard(), .remove() & .pop()
│ │ │ └── Solution.py
│ │ ├── Set .intersection() Operation
│ │ │ └── Solution.py
│ │ ├── Set .symmetric_difference() Operation
│ │ │ └── Solution.py
│ │ ├── Set .union() Operation
│ │ │ └── Solution.py
│ │ ├── Set Mutations
│ │ │ └── Solution.py
│ │ ├── Symmetric Difference
│ │ │ └── Solution.py
│ │ └── The Captain's Room
│ │ │ └── Solution.py
│ ├── Strings
│ │ ├── Alphabet Rangoli
│ │ │ └── Solution.py
│ │ ├── Capitalize!
│ │ │ └── Solution.py
│ │ ├── Designer Door Mat
│ │ │ └── Solution.py
│ │ ├── Find a string
│ │ │ └── Solution.py
│ │ ├── Merge the Tools!
│ │ │ └── Solution.py
│ │ ├── Mutations
│ │ │ └── Solution.py
│ │ ├── String Formatting
│ │ │ └── Solution.py
│ │ ├── String Split and Join
│ │ │ └── Solution.py
│ │ ├── String Validators
│ │ │ └── Solution.py
│ │ ├── Text Alignment
│ │ │ └── Solution.py
│ │ ├── Text Wrap
│ │ │ └── Solution.py
│ │ ├── The Minion Game
│ │ │ └── Solution.py
│ │ ├── What's Your Name
│ │ │ └── Solution.py
│ │ └── sWAP cASE
│ │ │ └── Solution.py
│ └── XML
│ │ ├── XML 1 - Find the Score
│ │ └── Solution.py
│ │ └── XML2 - Find the Maximum Depth
│ │ └── Solution.py
├── README.md
├── SQL
│ ├── Advanced Join
│ │ ├── 15 Days of Learning SQL
│ │ │ └── Solution.sql
│ │ ├── Interviews
│ │ │ └── Solution.sql
│ │ ├── Placements
│ │ │ └── Solution.sql
│ │ ├── Projects
│ │ │ └── Solution.sql
│ │ └── Symmetric Pairs
│ │ │ └── Solution.sql
│ ├── Advanced Select
│ │ ├── Binary Tree Nodes
│ │ │ └── Solution.sql
│ │ ├── New Companies
│ │ │ └── Solution.sql
│ │ ├── Occupations
│ │ │ └── Solution.sql
│ │ ├── The PADS
│ │ │ └── Solution.sql
│ │ └── Type of Triangle
│ │ │ └── Solution.sql
│ ├── Aggregation
│ │ ├── Average Population
│ │ │ └── Solution.sql
│ │ ├── Japan Population
│ │ │ └── Solution.sql
│ │ ├── Population Density Difference
│ │ │ └── Solution.sql
│ │ ├── Revising Aggregations - Averages
│ │ │ └── Solution.sql
│ │ ├── Revising Aggregations - The Count Function
│ │ │ └── Solution.sql
│ │ ├── Revising Aggregations - The Sum Function
│ │ │ └── Solution.sql
│ │ ├── The Blunder
│ │ │ └── Solution.sql
│ │ ├── Top Earners
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 13
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 14
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 15
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 16
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 17
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 18
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 19
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 2
│ │ │ └── Solution.sql
│ │ └── Weather Observation Station 20
│ │ │ └── Solution.sql
│ ├── Alternative Queries
│ │ ├── Draw The Triangle 1
│ │ │ └── Solution.sql
│ │ ├── Draw The Triangle 2
│ │ │ └── Solution.sql
│ │ └── Print Prime Numbers
│ │ │ └── Solution.sql
│ ├── Basic Join
│ │ ├── African Cities
│ │ │ └── Solution.sql
│ │ ├── Asian Population
│ │ │ └── Solution.sql
│ │ ├── Average Population of Each Continent
│ │ │ └── Solution.sql
│ │ ├── Challenges
│ │ │ └── Solution.sql
│ │ ├── Contest Leaderboard
│ │ │ └── Solution.sql
│ │ ├── Ollivander's Inventory
│ │ │ └── Solution.sql
│ │ ├── The Report
│ │ │ └── Solution.sql
│ │ └── Top Competitors
│ │ │ └── Solution.sql
│ ├── Basic Select
│ │ ├── Employee Names
│ │ │ └── Solution.sql
│ │ ├── Employee Salaries
│ │ │ └── Solution.sql
│ │ ├── Higher Than 75 Marks
│ │ │ └── Solution.sql
│ │ ├── Japanese Cities' Attributes
│ │ │ └── Solution.sql
│ │ ├── Japanese Cities' Names
│ │ │ └── Solution.sql
│ │ ├── Revising the Select Query I
│ │ │ └── Solution.sql
│ │ ├── Revising the Select Query II
│ │ │ └── Solution.sql
│ │ ├── Select All
│ │ │ └── Solution.sql
│ │ ├── Select By ID
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 1
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 10
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 11
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 12
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 3
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 4
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 5
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 6
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 7
│ │ │ └── Solution.sql
│ │ ├── Weather Observation Station 8
│ │ │ └── Solution.sql
│ │ └── Weather Observation Station 9
│ │ │ └── Solution.sql
│ └── README.md
└── pom.xml
├── HackerRank2
├── README.md
├── contest
│ ├── 101_hack_january_2015
│ │ └── AngryProfessor.java
│ ├── ad_infinitum13
│ │ ├── DeletionGame.java
│ │ ├── GameWithCoins.java
│ │ ├── IntegralPoints.java
│ │ ├── Multiply.java
│ │ └── integral_points.rb
│ ├── ad_infinitum9
│ │ └── MergeList.java
│ ├── cisco
│ │ ├── BigFileSystemSearch.java
│ │ └── SecurePasswordSystem.java
│ ├── contest.iml
│ ├── epiccode
│ │ └── PerfectHiring.java
│ ├── lambda_calculi9
│ │ ├── ListAndGcd.scala
│ │ ├── MinumumMultiple.scala
│ │ ├── StockPediction.scala
│ │ └── StringReductions.scala
│ ├── lambda_calculi_march_2016
│ │ ├── ComputePolygonArea.scala
│ │ ├── ComputePolygonPerimeter.scala
│ │ ├── ConcavePolygon.scala
│ │ └── FunctionOrNot.scala
│ ├── project_euler+
│ │ ├── 001_multiples_of_3_and_5
│ │ │ └── Multiples.java
│ │ ├── 002_even_fibonacci_numbers
│ │ │ └── even_fibonacci.rb
│ │ ├── 003_largest_prime_factor
│ │ │ └── LargestPrimeFactors.java
│ │ ├── 004_largest_palindrome_product
│ │ │ └── LargestPalindromeProduct.java
│ │ ├── 005_smallest_multiple
│ │ │ └── SmallestMultiple.java
│ │ ├── 006_sum_square_difference
│ │ │ └── SumSquareDifference.java
│ │ ├── 007_10001st_prime
│ │ │ └── Prime10001st.java
│ │ ├── 008_largest_product_in_a_series
│ │ │ └── LargestProduct.java
│ │ ├── 009_special_pythagorean_triplet
│ │ │ └── PythagoreanTriplet.java
│ │ ├── 010_summation_of_primes
│ │ │ └── SummationPrimes.java
│ │ ├── 011_largest_product_in_a_grid
│ │ │ └── LargestProductGrid.java
│ │ ├── 012_highly_divisible_triangular_number
│ │ │ └── HighlyDivisibleTriangularNumber.java
│ │ ├── 013_large_sum
│ │ │ └── LargeSum.java
│ │ ├── 014_longest_collatz_sequence
│ │ │ └── LongestCollatzSequence.java
│ │ ├── 015_lattice_paths
│ │ │ └── LatticePaths.java
│ │ ├── 016_power_digit_sum
│ │ │ └── PowerDigitSum.java
│ │ ├── 017_number_to_words
│ │ │ └── NumberToWords.java
│ │ ├── 018_maximum_path_sum_i
│ │ │ └── MaximumPathSum1.java
│ │ ├── 019_counting_sundays
│ │ │ └── counting_sundays.rb
│ │ ├── 020_factorial_digit_sum
│ │ │ └── factorial_digit_sum.rb
│ │ ├── 022_names_scores
│ │ │ └── NameScores.java
│ │ ├── 036_double-base_palindromes
│ │ │ └── DoubleBasePalindromes.java
│ │ ├── 067_maximum_path_sum_ii
│ │ │ └── MaximumPathSum2.java
│ │ └── project_euler+.iml
│ ├── week_of_code_16
│ │ └── SumOfAbsolutes.java
│ ├── week_of_code_22
│ │ ├── CookieParty.scala
│ │ ├── MakingPolygons.java
│ │ └── MatchingSets.scala
│ ├── week_of_code_23
│ │ ├── GearsOfWar.scala
│ │ └── Lighthouse.java
│ ├── week_of_code_24
│ │ ├── AppleAndOrange.scala
│ │ └── HappyLadybugs.scala
│ ├── week_of_code_25
│ │ ├── AppendAndDelete.scala
│ │ └── BetweenTwoSets.scala
│ └── weekly
│ │ ├── week11
│ │ └── SherlockSquares.java
│ │ ├── week12
│ │ └── PriyankaAndToys.java
│ │ ├── week13
│ │ ├── SherlockAndAnagrams.java
│ │ └── TaumAndBday.java
│ │ ├── week6
│ │ ├── AcmIcpcTeam.java
│ │ └── ConsecutiveSubsequences.java
│ │ └── weekly.iml
├── pom.xml
└── practice
│ ├── algorithms
│ ├── bit_manipulation
│ │ ├── bit_manipulation.iml
│ │ ├── flipping_bits
│ │ │ ├── FlippingBits.java
│ │ │ ├── FlippingBits.js
│ │ │ ├── FlippingBits.scala
│ │ │ └── flipping_bits.rb
│ │ ├── lonely_integer
│ │ │ ├── LonelyInteger.java
│ │ │ ├── LonelyInteger.js
│ │ │ ├── LonelyInteger.scala
│ │ │ └── lonely_integer.rb
│ │ ├── maximizing_xor
│ │ │ ├── MaximizingXor.java
│ │ │ ├── MaximizingXor.js
│ │ │ ├── MaximizingXor.scala
│ │ │ └── maximizing_xor.rb
│ │ └── sum_vs_xor
│ │ │ ├── SumVsXor.java
│ │ │ ├── SumVsXor.js
│ │ │ ├── SumVsXor.scala
│ │ │ └── sum_vs_xor.rb
│ ├── code_golf
│ │ └── fizzbuzz
│ │ │ └── Solution.scala
│ ├── dynamic_programming
│ │ ├── dynamic_programming.iml
│ │ └── max_subarray
│ │ │ ├── MaxSubarray.java
│ │ │ ├── MaxSubarray.js
│ │ │ ├── MaxSubarray.scala
│ │ │ └── max_subarray.rb
│ ├── graph_theory
│ │ ├── even_tree
│ │ │ ├── EvenTree.java
│ │ │ ├── EvenTree.js
│ │ │ ├── EvenTree.scala
│ │ │ └── even_tree.rb
│ │ ├── graph_theory.iml
│ │ └── snakes_and_ladders_the_quickest_way_up
│ │ │ └── snakes_ladders.rb
│ ├── greedy
│ │ ├── flowers
│ │ │ ├── Flowers.java
│ │ │ ├── Flowers.js
│ │ │ ├── Flowers.scala
│ │ │ └── flowers.rb
│ │ ├── greedy.iml
│ │ ├── mark_and_toys
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── max_min
│ │ │ ├── MaxMin.java
│ │ │ ├── MaxMin.js
│ │ │ ├── MaxMin.scala
│ │ │ └── angry_children.rb
│ │ ├── priyanka_and_toys
│ │ │ ├── PriyankaAndToys.java
│ │ │ ├── PriyankaAndToys.js
│ │ │ └── PriyankaAndToys.scala
│ │ └── two_arrays
│ │ │ ├── TwoArrays.java
│ │ │ ├── TwoArrays.js
│ │ │ ├── TwoArrays.scala
│ │ │ └── two_arrays.rb
│ ├── implementation
│ │ ├── acm_icpc_team
│ │ │ ├── AcmIcpcTeam.java
│ │ │ ├── AcmIcpcTeam.js
│ │ │ └── AcmIcpcTeam.scala
│ │ ├── angry_professor
│ │ │ ├── AngryProfessor.java
│ │ │ ├── AngryProfessor.js
│ │ │ ├── AngryProfessor.scala
│ │ │ └── angry_professor.rb
│ │ ├── apple_and_orange
│ │ │ ├── AppleAndOrange.java
│ │ │ ├── AppleAndOrange.js
│ │ │ ├── AppleAndOrange.scala
│ │ │ └── apple_and_orange.rb
│ │ ├── beautiful_days_at_the_movies
│ │ │ ├── BeautifulDaysAtTheMovies.java
│ │ │ ├── BeautifulDaysAtTheMovies.js
│ │ │ ├── BeautifulDaysAtTheMovies.scala
│ │ │ └── beautiful_days_at_the_movies.rb
│ │ ├── beautiful_triplets
│ │ │ ├── BeautifulTriplets.java
│ │ │ ├── BeautifulTriplets.js
│ │ │ ├── BeautifulTriplets.scala
│ │ │ └── beautiful_triplets.rb
│ │ ├── between_two_sets
│ │ │ ├── BetweenTwoSets.java
│ │ │ ├── BetweenTwoSets.js
│ │ │ ├── BetweenTwoSets.scala
│ │ │ └── between_two_sets.rb
│ │ ├── birthday_chocolate
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── bon_appetit
│ │ │ ├── BonAppetit.java
│ │ │ ├── BonAppetit.js
│ │ │ ├── BonAppetit.scala
│ │ │ └── bon_appetit.rb
│ │ ├── breaking_the_records
│ │ │ ├── BreakingTheRecords.java
│ │ │ ├── BreakingTheRecords.js
│ │ │ └── BreakingTheRecords.scala
│ │ ├── caesar_cipher
│ │ │ ├── CaesarCipher.java
│ │ │ ├── CaesarCipher.js
│ │ │ ├── CaesarCipher.scala
│ │ │ └── caesar_cipher.rb
│ │ ├── cats_and_a_mouse
│ │ │ ├── CatsAndMouse.java
│ │ │ ├── CatsAndMouse.js
│ │ │ └── CatsAndMouse.scala
│ │ ├── cavity_map
│ │ │ ├── CavityMap.java
│ │ │ ├── CavityMap.js
│ │ │ ├── CavityMap.scala
│ │ │ └── cavity_map.rb
│ │ ├── chocolate_feast
│ │ │ ├── ChocolateFeast.java
│ │ │ ├── ChocolateFeast.js
│ │ │ ├── ChocolateFeast.scala
│ │ │ └── chocolate_feast.rb
│ │ ├── counting_valleys
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── cut_the_sticks
│ │ │ ├── CutTheSticks.java
│ │ │ ├── CutTheSticks.js
│ │ │ ├── CutTheSticks.scala
│ │ │ └── cut_the_sticks.rb
│ │ ├── day_of_the_programmer
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── designer_pdf_viewer
│ │ │ ├── DesignerPdfViewer.java
│ │ │ ├── DesignerPdfViewer.js
│ │ │ ├── DesignerPdfViewer.scala
│ │ │ └── designer_pdf_viewer.rb
│ │ ├── divisible_sum_pairs
│ │ │ ├── DivisibleSumPairs.java
│ │ │ ├── DivisibleSumPairs.js
│ │ │ ├── DivisibleSumPairs.scala
│ │ │ └── divisible_sum_pairs.rb
│ │ ├── drawing_book
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── electronics_shop
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── encryption
│ │ │ ├── Encryption.java
│ │ │ ├── Encryption.js
│ │ │ ├── Encryption.scala
│ │ │ └── encryption.rb
│ │ ├── equalize_the_array
│ │ │ ├── EqualizeTheArray.java
│ │ │ ├── EqualizeTheArray.js
│ │ │ ├── EqualizeTheArray.scala
│ │ │ └── equalize_the_array.rb
│ │ ├── extra_long_factorials
│ │ │ ├── ExtraLongFactorials.java
│ │ │ ├── ExtraLongFactorials.js
│ │ │ ├── ExtraLongFactorials.scala
│ │ │ └── extra_long_factorials.rb
│ │ ├── find_digits
│ │ │ ├── FindDigits.java
│ │ │ ├── FindDigits.js
│ │ │ ├── FindDigits.scala
│ │ │ └── find_digits.rb
│ │ ├── flatland_space_stations
│ │ │ ├── FlatlandSpaceStations.scala
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.rb
│ │ ├── grading_students
│ │ │ ├── GradingStudents.java
│ │ │ ├── GradingStudents.js
│ │ │ ├── GradingStudents.scala
│ │ │ └── grading_students.rb
│ │ ├── implementation.iml
│ │ ├── jumping_on_the_clouds
│ │ │ ├── JumpingOnTheClouds.java
│ │ │ ├── JumpingOnTheClouds.js
│ │ │ ├── JumpingOnTheClouds.scala
│ │ │ └── jumping_on_the_clouds.rb
│ │ ├── jumping_on_the_clouds_revisited
│ │ │ ├── JumpingOnTheCloudsRevisited.java
│ │ │ ├── JumpingOnTheCloudsRevisited.js
│ │ │ ├── JumpingOnTheCloudsRevisited.scala
│ │ │ └── jumping_on_the_clouds_revisited.rb
│ │ ├── kangaroo
│ │ │ ├── Kangaroo.java
│ │ │ ├── Kangaroo.js
│ │ │ ├── Kangaroo.scala
│ │ │ └── kangaroo.rb
│ │ ├── library_fine
│ │ │ ├── LibraryFine.java
│ │ │ ├── LibraryFine.js
│ │ │ ├── LibraryFine.scala
│ │ │ └── library_fine.rb
│ │ ├── lisas_workbook
│ │ │ ├── LisasWorkbook.java
│ │ │ ├── LisasWorkbook.js
│ │ │ ├── LisasWorkbook.scala
│ │ │ └── lisas_workbook.rb
│ │ ├── manasa_and_stones
│ │ │ ├── ManasaAndStones.java
│ │ │ ├── ManasaAndStones.js
│ │ │ ├── ManasaAndStones.scala
│ │ │ └── manasa_stones.rb
│ │ ├── migratory_birds
│ │ │ ├── MigratoryBirds.java
│ │ │ ├── MigratoryBirds.js
│ │ │ └── MigratoryBirds.scala
│ │ ├── mini-max_sum
│ │ │ ├── MinMaxSum.js
│ │ │ ├── MinMaxSum.scala
│ │ │ ├── MiniMaxSum.java
│ │ │ └── min_max_sum.rb
│ │ ├── minimum_distances
│ │ │ ├── MinimumDistances.java
│ │ │ ├── MinimumDistances.scala
│ │ │ ├── MinumuDistances.js
│ │ │ └── minimum_distances.rb
│ │ ├── modified_kaprekar_numbers
│ │ │ ├── ModifiedKaprekarNumbers.java
│ │ │ ├── ModifiedKaprekarNumbers.js
│ │ │ ├── ModifiedKaprekarNumbers.scala
│ │ │ └── modified_kaprekar_numbers.rb
│ │ ├── picking_numbers
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── repeated_string
│ │ │ ├── RepeatedString.java
│ │ │ ├── RepeatedString.js
│ │ │ ├── RepeatedString.scala
│ │ │ └── repeated_string.rb
│ │ ├── save_the_prisoner
│ │ │ ├── SaveThePrisoner.java
│ │ │ ├── SaveThePrisoner.js
│ │ │ ├── SaveThePrisoner.scala
│ │ │ └── save_the_prisoner.rb
│ │ ├── sequence_equation
│ │ │ ├── SequenceEquation.java
│ │ │ ├── SequenceEquation.js
│ │ │ ├── SequenceEquation.scala
│ │ │ └── Solution.scala
│ │ ├── service_lane
│ │ │ ├── ServiceLane.java
│ │ │ ├── ServiceLane.js
│ │ │ ├── ServiceLane.scala
│ │ │ └── service_lane.rb
│ │ ├── sherlock_and_squares
│ │ │ ├── SherlockAndSquares.java
│ │ │ ├── SherlockAndSquares.js
│ │ │ ├── SherlockAndSquares.scala
│ │ │ └── sherlock_and_squares.rb
│ │ ├── sherlock_and_the_beast
│ │ │ ├── SherlockAndBeast.scala
│ │ │ ├── SherlockBeast.java
│ │ │ ├── SherlockBeast.js
│ │ │ └── sherlock_beast.rb
│ │ ├── sock_merchant
│ │ │ ├── SockMerchant.java
│ │ │ ├── SockMerchant.js
│ │ │ ├── SockMerchant.scala
│ │ │ └── sock_merchant.rb
│ │ ├── strange_counter
│ │ │ ├── StrangeCounter.java
│ │ │ ├── StrangeCounter.js
│ │ │ ├── StrangeCounter.scala
│ │ │ └── strange_counter.rb
│ │ ├── taum_and_bday
│ │ │ ├── TaumAndBday.java
│ │ │ ├── TaumAndBday.js
│ │ │ └── TaumAndBday.scala
│ │ ├── the_hurdle_race
│ │ │ ├── HurdleRace.java
│ │ │ ├── TheHurdleRace.js
│ │ │ ├── TheHurdleRace.scala
│ │ │ └── the_hurdle_race.rb
│ │ ├── utopian_tree
│ │ │ ├── UtopianTree.java
│ │ │ ├── UtopianTree.js
│ │ │ ├── UtopianTree.scala
│ │ │ └── utopian_tree.rb
│ │ └── viral_advertising
│ │ │ ├── ViralAdvertising.java
│ │ │ ├── ViralAdvertising.js
│ │ │ ├── ViralAdvertising.scala
│ │ │ └── viral_advertising.rb
│ ├── search
│ │ ├── ice_cream_parlor
│ │ │ ├── IceCreamParlor.java
│ │ │ ├── IceCreamParlor.js
│ │ │ ├── IceCreamParlor.scala
│ │ │ └── ice_cream_parlor.rb
│ │ ├── missing_numbers
│ │ │ ├── MissingNumbers.java
│ │ │ ├── MissingNumbers.js
│ │ │ ├── MissingNumbers.scala
│ │ │ └── missing_numbers.rb
│ │ ├── pairs
│ │ │ ├── Pairs.java
│ │ │ ├── Pairs.js
│ │ │ ├── Pairs.scala
│ │ │ └── pairs.rb
│ │ └── search.iml
│ ├── sorting
│ │ ├── closest_numbers
│ │ │ ├── ClosestNumbers.java
│ │ │ ├── ClosestNumbers.js
│ │ │ ├── ClosestNumbers.scala
│ │ │ └── closest_numbers.rb
│ │ ├── correctness_and_the_loop_invariant
│ │ │ └── Solution.java
│ │ ├── counting_sort_1
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── counting_sort_2
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── insertion_sort-part_1
│ │ │ ├── InsertionSort1.java
│ │ │ ├── InsertionSort1.js
│ │ │ ├── InsertionSort1.scala
│ │ │ └── insertion_sort1.rb
│ │ ├── insertion_sort-part_2
│ │ │ └── Solution.java
│ │ ├── intro_to_tutorial_challenges
│ │ │ ├── IntroToTutorialChallenges.java
│ │ │ ├── IntroToTutorialChallenges.js
│ │ │ ├── IntroToTutorialChallenges.scala
│ │ │ └── intro_to_tutorial_challenges.rb
│ │ └── sorting.iml
│ ├── strings
│ │ ├── alternating_characters
│ │ │ ├── AlternatingCharacters.java
│ │ │ ├── AlternatingCharacters.js
│ │ │ ├── AlternatingCharacters.scala
│ │ │ └── alternating_characters.rb
│ │ ├── anagram
│ │ │ ├── Anagram.java
│ │ │ ├── Anagram.js
│ │ │ ├── Anagram.scala
│ │ │ └── anagram.rb
│ │ ├── beautiful_binary_string
│ │ │ ├── BeautifulBinaryString.java
│ │ │ ├── BeautifulBinaryString.js
│ │ │ ├── BeautifulBinaryString.scala
│ │ │ └── beautiful_binary_string.rb
│ │ ├── camelcase
│ │ │ ├── CamelCase.java
│ │ │ ├── CamelCase.js
│ │ │ ├── CamelCase.scala
│ │ │ └── camelcase.rb
│ │ ├── common_child
│ │ │ ├── CommonChild.java
│ │ │ └── common_child.rb
│ │ ├── funny_string
│ │ │ ├── FunnyString.java
│ │ │ ├── FunnyString.js
│ │ │ ├── FunnyString.scala
│ │ │ └── funny_string.rb
│ │ ├── game_of_thrones-i
│ │ │ ├── GameOfThrones1.java
│ │ │ ├── GameOfThrones1.js
│ │ │ ├── GameOfThrones1.scala
│ │ │ └── game_of_thrones1.rb
│ │ ├── gemstones
│ │ │ ├── GemStones.java
│ │ │ ├── Gemstones.js
│ │ │ ├── Gemstones.scala
│ │ │ └── gemstones.rb
│ │ ├── making_anagrams
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ ├── mars_exploration
│ │ │ ├── MarsExploration.java
│ │ │ ├── MarsExploration.js
│ │ │ ├── MarsExploration.scala
│ │ │ └── mars_exploration.rb
│ │ ├── pangrams
│ │ │ ├── Pangrams.java
│ │ │ ├── Pangrams.js
│ │ │ ├── Pangrams.scala
│ │ │ └── pangrams.rb
│ │ ├── separate_the_numbers
│ │ │ ├── Solution.java
│ │ │ └── solution.js
│ │ ├── sherlock_and_anagrams
│ │ │ └── SherlockAndAnagrams.java
│ │ ├── string_construction
│ │ │ ├── StringConstruction.java
│ │ │ ├── StringConstruction.js
│ │ │ ├── StringConstruction.scala
│ │ │ └── string_construction.rb
│ │ ├── strings.iml
│ │ ├── super_reduced_string
│ │ │ ├── SuperReducedString.java
│ │ │ ├── SuperReducedString.js
│ │ │ ├── SuperReducedString.scala
│ │ │ └── super_reduced_string.rb
│ │ ├── the_love-letter_mystery
│ │ │ ├── LoveLetterMystery.java
│ │ │ ├── TheLoveLetterMystery.js
│ │ │ ├── TheLoveLetterMystery.scala
│ │ │ └── loveletter_mystery.rb
│ │ ├── two_characters
│ │ │ ├── Solution.java
│ │ │ ├── solution.js
│ │ │ └── solution.scala
│ │ └── weighted_uniform_strings
│ │ │ ├── WeightedUniformStrings.java
│ │ │ ├── WeightedUniformStrings.js
│ │ │ └── WeightedUniformStrings.scala
│ └── warmup
│ │ ├── a_very_big_sum
│ │ ├── AVeryBigSum.java
│ │ ├── AVeryBigSum.js
│ │ ├── AVeryBigSum.scala
│ │ └── a_very_big_sum.rb
│ │ ├── birthday_cake_candles
│ │ ├── BirthdayCakeCandles.java
│ │ ├── BirthdayCakeCandles.js
│ │ └── BirthdayCakeCandles.scala
│ │ ├── circular_array_rotation
│ │ ├── CircularArrayRotation.java
│ │ ├── CircularArrayRotation.js
│ │ ├── CircularArrayRotation.scala
│ │ └── circular_array_rotation.rb
│ │ ├── compare_the_triplets
│ │ ├── CompareTheTriplets.java
│ │ ├── CompareTheTriplets.js
│ │ ├── CompareTheTriplets.scala
│ │ └── compare_the_triplets.rb
│ │ ├── diagonal_difference
│ │ ├── DiagonalDifference.java
│ │ ├── DiagonalDifference.js
│ │ ├── DiagonalDifference.scala
│ │ └── diagonal_difference.rb
│ │ ├── plus_minus
│ │ ├── PlusMinus.java
│ │ ├── PlusMinus.js
│ │ ├── PlusMinus.scala
│ │ └── plus_minus.rb
│ │ ├── simple_array_sum
│ │ ├── SimpleArraySum.java
│ │ ├── SimpleArraySum.js
│ │ ├── SimpleArraySum.scala
│ │ └── simple_array_sum.rb
│ │ ├── solve_me_first
│ │ ├── SolveMeFirst.java
│ │ ├── SolveMeFirst.js
│ │ ├── SolveMeFirst.scala
│ │ └── solve_me_first.rb
│ │ ├── solve_me_second
│ │ ├── SolveMeSecond.java
│ │ ├── SolveMeSecond.js
│ │ ├── SolveMeSecond.scala
│ │ └── solve_me_second.rb
│ │ ├── staircase
│ │ ├── Staircase.java
│ │ ├── Staircase.js
│ │ ├── Staircase.scala
│ │ └── staircase.rb
│ │ ├── time_conversion
│ │ ├── TimeConversion.java
│ │ ├── TimeConversion.js
│ │ ├── TimeConversion.scala
│ │ └── time_conversion.rb
│ │ └── warmup.iml
│ ├── data_structures
│ ├── arrays
│ │ └── arrays-ds
│ │ │ ├── ArrayDS.java
│ │ │ ├── ArrayDS.js
│ │ │ ├── ArraysDS.scala
│ │ │ └── arrays_ds.rb
│ ├── data_structures.iml
│ └── linked_lists
│ │ └── print_the_elements_of_a_linked_list
│ │ └── PrintTheElementsOfALinkedList.java
│ ├── functional_programming
│ ├── ad_hoc
│ │ ├── jumping_bunnies
│ │ │ └── JumpingBunnies.scala
│ │ ├── missing_numbers_fp
│ │ │ └── MissingNumbers.scala
│ │ ├── remove_duplicates
│ │ │ └── RemoveDuplicates.scala
│ │ └── rotate_string
│ │ │ └── RotateString.scala
│ ├── introduction
│ │ ├── area_under_curves_and_volume_of_revolving_a_curve
│ │ │ └── AreaUnderCurves.scala
│ │ ├── array_of_n_elements
│ │ │ └── ArrayOfN.scala
│ │ ├── compute_the_area_of_a_polygon
│ │ │ └── ComputePolygonArea.scala
│ │ ├── compute_the_perimeter_of_a_polygon
│ │ │ └── ComputePolygonPerimeter.scala
│ │ ├── evaluating_e^x
│ │ │ └── EvaluatingEx.scala
│ │ ├── filter_array
│ │ │ └── FilterArray.scala
│ │ ├── filter_positions_in_a_list
│ │ │ └── FilterPositions.scala
│ │ ├── functions_or_not
│ │ │ └── FunctionOrNot.scala
│ │ ├── hello_world
│ │ │ └── HelloWorld.scala
│ │ ├── hello_world_n_times
│ │ │ └── HelloWorldNTimes.scala
│ │ ├── lambda_calculus-evaluating_expressions_1
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-evaluating_expressions_2
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-evaluating_expressions_3
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-evaluating_expressions_4
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-evaluating_expressions_5
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-reductions_1
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-reductions_2
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-reductions_3
│ │ │ └── solution.txt
│ │ ├── lambda_calculus-reductions_4
│ │ │ └── solution.txt
│ │ ├── list_length
│ │ │ └── ListLength.scala
│ │ ├── list_replication
│ │ │ └── ListReplication.scala
│ │ ├── reverse_a_list
│ │ │ └── ReverseList.scala
│ │ ├── solve_me_first_fp
│ │ │ └── SolveMeFirst.scala
│ │ ├── sum_of_odd_elements
│ │ │ └── SumOddElements.scala
│ │ └── update_list
│ │ │ └── UpdateList.scala
│ └── recursion
│ │ ├── computing_the_gcd
│ │ └── ComputingGcd.scala
│ │ ├── fibonacci_numbers
│ │ └── FibonacciNumbers.scala
│ │ ├── filter_elements
│ │ └── solution.scala
│ │ ├── pascals_triangle
│ │ └── PascalTriangle.scala
│ │ ├── prefix_compression
│ │ └── PrefixCompression.scala
│ │ ├── sequence_full_of_colors
│ │ └── SequenceFullOfColors.scala
│ │ ├── string-o-permute
│ │ └── StringOPermute.scala
│ │ ├── string_compression
│ │ └── Solution.scala
│ │ ├── string_mingling
│ │ └── StringMingling.scala
│ │ ├── string_reductions
│ │ └── StringReductions.scala
│ │ └── super_digit
│ │ └── SuperDigit.scala
│ ├── java
│ ├── introduction
│ │ ├── introduction.iml
│ │ ├── java_currency_formatter
│ │ │ └── Solution.java
│ │ ├── java_datatypes
│ │ │ └── Solution.java
│ │ ├── java_date_and_time
│ │ │ └── Solution.java
│ │ ├── java_end-of-file
│ │ │ └── Solution.java
│ │ ├── java_if-else
│ │ │ └── JavaIfElse.java
│ │ ├── java_int_to_string
│ │ │ └── Solution.java
│ │ ├── java_loops_i
│ │ │ └── Solution.java
│ │ ├── java_loops_ii
│ │ │ └── Solution.java
│ │ ├── java_output_formatting
│ │ │ └── Solution.java
│ │ ├── java_static_initializer_block
│ │ │ └── Solution.java
│ │ ├── java_stdin_and_stdout_1
│ │ │ └── JavaStdinAndStdout1.java
│ │ ├── java_stdin_and_stdout_2
│ │ │ └── Solution.java
│ │ └── welcome_to_java
│ │ │ └── WelcomeToJava.java
│ └── strings
│ │ ├── java_strings_introduction
│ │ └── JavaStringsIntroduction.java
│ │ └── strings1.iml
│ ├── linux_shell
│ ├── bash
│ │ ├── a_personalized_echo
│ │ │ └── a_personalized_echo.sh
│ │ ├── comparing_numbers
│ │ │ └── comparing_numbers.sh
│ │ ├── getting_started_with_conditionals
│ │ │ └── getting_started_with_conditionals.sh
│ │ ├── lets_echo
│ │ │ └── lets_echo.sh
│ │ ├── looping_and_skipping
│ │ │ └── looping_and_skipping.sh
│ │ ├── looping_with_numbers
│ │ │ └── looping_with_numbers.sh
│ │ └── the_world_of_numbers
│ │ │ └── the_world_of_numbers.sh
│ ├── grep_sed_awk
│ │ ├── grep_1
│ │ │ └── the_grep_command1.sh
│ │ └── grep_2
│ │ │ └── the_grep_command2.sh
│ └── text_processing
│ │ ├── cut_1
│ │ └── the_cut_command1.sh
│ │ ├── cut_2
│ │ └── the_cut_command2.sh
│ │ ├── head_of_a_text_file_1
│ │ └── the_head_of_text_file1.sh
│ │ ├── head_of_a_text_file_2
│ │ └── the_head_of_text_file2.sh
│ │ ├── sort_command_1
│ │ └── the_sort_command1.sh
│ │ ├── sort_command_2
│ │ └── the_sort_command2.sh
│ │ ├── tr_command_1
│ │ └── the_tr_command1.sh
│ │ └── tr_command_2
│ │ └── the_tr_command2.sh
│ ├── mathematics
│ ├── combinatorics
│ │ ├── building_a_list
│ │ │ ├── BuildingList.java
│ │ │ ├── BuildingList.js
│ │ │ └── building_list.rb
│ │ ├── combinatorics.iml
│ │ ├── consecutive_subsequences
│ │ │ └── ConsecutiveSubsequences.java
│ │ └── picking_cards
│ │ │ ├── PickingCards.java
│ │ │ ├── PickingCards.js
│ │ │ ├── PickingCards.scala
│ │ │ └── picking_cards.rb
│ ├── fundamentals
│ │ ├── connecting_towns
│ │ │ ├── ConnectingTowns.java
│ │ │ ├── ConnectingTowns.js
│ │ │ ├── ConnectingTowns.scala
│ │ │ └── connecting_towns.rb
│ │ ├── filling_jars
│ │ │ ├── FillingJars.java
│ │ │ ├── FillingJars.js
│ │ │ ├── FillingJars.scala
│ │ │ └── filling_jars.rb
│ │ ├── find_point
│ │ │ ├── FindPoint.java
│ │ │ ├── FindPoint.js
│ │ │ ├── FindPoint.scala
│ │ │ └── find_point.rb
│ │ ├── fundamentals.iml
│ │ ├── halloween_party
│ │ │ ├── HalloweenParty.java
│ │ │ ├── HalloweenParty.js
│ │ │ ├── HalloweenParty.scala
│ │ │ └── halloween_party.rb
│ │ ├── handshake
│ │ │ ├── Handshake.java
│ │ │ ├── Handshake.js
│ │ │ ├── Handshake.scala
│ │ │ └── handshake.rb
│ │ ├── is_fibo
│ │ │ ├── IsFibo.java
│ │ │ ├── IsFibo.js
│ │ │ ├── IsFibo.scala
│ │ │ └── is_fibo.rb
│ │ └── minimum_draws
│ │ │ ├── MinimumDraws.java
│ │ │ ├── MinimumDraws.js
│ │ │ ├── MinimumDraws.scala
│ │ │ └── minimum_draws.rb
│ ├── number_theory
│ │ ├── equations
│ │ │ ├── Equations.java
│ │ │ ├── Equations.js
│ │ │ ├── Equations.scala
│ │ │ └── equations.rb
│ │ └── number_theory.iml
│ └── probability
│ │ ├── bday_gift
│ │ ├── BdayGift.java
│ │ ├── BdayGift.js
│ │ ├── BdayGift.scala
│ │ └── bday_gift.rb
│ │ └── probability.iml
│ ├── regex
│ ├── applications
│ │ ├── alien_username
│ │ │ ├── AlienUsername.java
│ │ │ ├── AlienUsername.js
│ │ │ ├── AlienUsername.scala
│ │ │ └── alien_username.rb
│ │ ├── detect_html_attributes
│ │ │ ├── DetectHtmlAttributes.java
│ │ │ └── DetectHtmlAttributes.scala
│ │ ├── detect_html_tags
│ │ │ ├── DetectHtmlTags.java
│ │ │ ├── DetectHtmlTags.js
│ │ │ ├── DetectHtmlTags.scala
│ │ │ └── detect_html_tags.rb
│ │ ├── detecting_valid_latitude_and_longitude_pairs
│ │ │ ├── LatitudeLongitudePairs.java
│ │ │ ├── LatituteLongitudePair.js
│ │ │ ├── LatituteLongitudePair.scala
│ │ │ └── valid_latitude_longitude.rb
│ │ ├── find_a_substring
│ │ │ ├── FindSubstring.java
│ │ │ ├── FindSubstring.js
│ │ │ ├── FindSubstring.scala
│ │ │ └── find_substring.rb
│ │ ├── find_hackerrank
│ │ │ ├── FindHackerRank.scala
│ │ │ ├── FindHackerrank.java
│ │ │ ├── FindHackerrank.js
│ │ │ └── find_hackerrank.rb
│ │ ├── hackerrank_tweets
│ │ │ ├── HackerrankTweets.java
│ │ │ ├── HackerrankTweets.js
│ │ │ ├── HackerrankTweets.scala
│ │ │ └── hackerrank_tweets.rb
│ │ ├── ip_address_validation
│ │ │ ├── IPAddressValidation.java
│ │ │ ├── IPAddressValidation.js
│ │ │ ├── IPAddressValidation.scala
│ │ │ └── ip_address_validation.rb
│ │ ├── split_the_phone_numbers
│ │ │ ├── SplitPhoneNumber.scala
│ │ │ ├── SplitPhoneNumbers.java
│ │ │ ├── SplitThePhoneNumbers.js
│ │ │ └── split_phone_numbers.rb
│ │ ├── the_british_and_american_style_of_spelling
│ │ │ ├── AmericanEnglishSpelling.scala
│ │ │ ├── BritishAmericanSpelling.js
│ │ │ ├── BritishAndAmericanSpelling.java
│ │ │ └── american_english_spelling.rb
│ │ └── valid_pan_format
│ │ │ ├── ValidPanFormat.java
│ │ │ ├── ValidPanFormat.js
│ │ │ ├── ValidPanFormat.scala
│ │ │ └── pan_format.rb
│ ├── character_class
│ │ ├── excluding_specific_characters
│ │ │ └── solution.txt
│ │ ├── matching_range_of_characters
│ │ │ └── solution.txt
│ │ └── matching_specific_characters
│ │ │ └── solution.txt
│ ├── grouping_and_capturing
│ │ ├── alternative_matching
│ │ │ └── solution.txt
│ │ ├── capturing_non-capturing_groups
│ │ │ └── solution.txt
│ │ └── matching_word_boundaries
│ │ │ └── solution.txt
│ ├── introduction
│ │ ├── matching_anything_but_a_newline
│ │ │ └── solution.txt
│ │ ├── matching_digits_non-digit_characters
│ │ │ └── solution.txt
│ │ ├── matching_specific_string
│ │ │ └── solution.txt
│ │ ├── matching_start_end
│ │ │ └── solution.txt
│ │ ├── matching_whitespace_non-whitespace_character
│ │ │ └── solution.txt
│ │ └── matching_word_non-word_character
│ │ │ └── solution.txt
│ ├── regex.iml
│ └── repetitions
│ │ ├── matching_ending_items
│ │ └── solution.txt
│ │ ├── matching_one_or_more_repetitions
│ │ └── solution.txt
│ │ ├── matching_x_repetitions
│ │ └── solution.txt
│ │ ├── matching_xy_repetitions
│ │ └── solution.txt
│ │ └── matching_zero_or_more_repetitions
│ │ └── solution.txt
│ └── sql
│ └── basic_select
│ ├── higher_than_75_marks
│ └── higher_than_75_marks.sql
│ ├── japanese_cities_detail
│ └── japanese_cities_detail.sql
│ ├── japanese_cities_names
│ └── japanese_cities_names.sql
│ ├── revising_the_select_query-1
│ └── revising_the_select_query_1.sql
│ ├── revising_the_select_query-2
│ └── revising_the_select_query_2.sql
│ ├── select_all
│ └── select_all.sql
│ ├── select_by_id
│ └── select_by_id.sql
│ ├── weather_observation_station_1
│ └── weather_observation_station_1.sql
│ ├── weather_observation_station_10
│ └── weather_observation_station_10.sql
│ ├── weather_observation_station_11
│ └── weather_observation_station_11.sql
│ ├── weather_observation_station_12
│ └── weather_observation_station_12.sql
│ ├── weather_observation_station_3
│ └── weather_observation_station_3.sql
│ ├── weather_observation_station_4
│ └── weather_observation_station_4.sql
│ ├── weather_observation_station_5
│ └── weather_observation_station_5.sql
│ ├── weather_observation_station_6
│ └── weather_observation_station_6.sql
│ ├── weather_observation_station_7
│ └── weather_observation_station_7.sql
│ ├── weather_observation_station_8
│ └── weather_observation_station_8.sql
│ └── weather_observation_station_9
│ └── weather_observation_station_9.sql
├── HackkerRank
├── pom.xml
└── src
│ └── test
│ └── java
│ └── JavaQuestions
│ ├── Balloon
│ ├── Image from iOS (1).jpg
│ ├── Image from iOS.jpg
│ └── Solution.java
│ ├── JacobsFavoriteNumber
│ ├── Jacob'sFavoriteNumber.png
│ ├── image (2).png
│ ├── image (3).png
│ ├── image (4).png
│ └── part1of1.png
│ ├── MakingAnagram
│ ├── MakingAnagram.java
│ ├── ProblemDescription.png
│ └── SampleCases.png
│ ├── MinumumSwapsToMakeStringsEqual
│ ├── QuestionExplanation
│ └── StringEqualization.java
│ ├── Minumum_Moves
│ ├── image (2).png
│ └── solution.java
│ ├── arraysandsorting
│ ├── InsertionSortPart1.java
│ ├── InsertionSortPart2.java
│ └── IntroToTutorialChallenges.java
│ ├── geometry
│ └── FindPoint.java
│ ├── implementation
│ ├── CavityMap.java
│ └── TheGridSearch.java
│ ├── q10
│ └── Hacker_ArrayLeftRotations.java
│ ├── q11
│ └── ArrayOfIntegers.java
│ ├── q5
│ ├── ArrayMaker.java
│ └── Main.java
│ ├── q6_7
│ ├── Image from iOS (1).jpg
│ ├── Image from iOS (2).jpg
│ ├── Image from iOS (3).jpg
│ ├── Image from iOS (4).jpg
│ ├── Image from iOS (5).jpg
│ └── Image from iOS.jpg
│ ├── q8
│ └── phpw391F4.png
│ ├── q9
│ └── Hacker_2DArrayDS.java
│ └── warmup
│ ├── ACMICPCTeam.java
│ ├── AlternatingCharacters.java
│ ├── AngryChildren.java
│ ├── ChocolateFeast.java
│ ├── FillingJars.java
│ ├── FindDigits.java
│ ├── FlippingBits.java
│ ├── GameOfThronesI.java
│ ├── HalloweenParty.java
│ ├── IsFibo.java
│ ├── LonelyInteger.java
│ ├── ManasaAndStones.java
│ ├── MaximizingXOR.java
│ ├── SherlockAndBeast.java
│ ├── SherlockAndGCD.java
│ ├── SherlockAndSquares.java
│ ├── SolveMeFirst.java
│ ├── SolveMeSecond.java
│ ├── TheLoveLetterMystery.java
│ └── UtopianTree.java
├── README.md
└── pom.xml
/.gitignore:
--------------------------------------------------------------------------------
1 | /.idea/
2 | /target/
3 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/HackerRank1/Cracking the Coding Interview/Algorithms/Sorting Comparator/Solution.java:
--------------------------------------------------------------------------------
1 | class Checker implements Comparator {
2 |
3 | @Override
4 | public int compare(Player p1, Player p2) {
5 | if (p1.score == p2.score) {
6 | return p1.name.compareTo(p2.name);
7 | } else {
8 | return p2.score - p1.score;
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Array Of N Elements/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(num: Int): List[Int] = (1 to num).toList
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Filter Array/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(delim: Int, arr: List[Int]): List[Int] = for (i <- arr if i < delim) yield i
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Filter Positions in a List/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(arr: List[Int]): List[Int] = {
2 | val elemsWithIndices = arr.zipWithIndex
3 | val filteredPairs = elemsWithIndices.filter(pair => pair._2 % 2 == 1)
4 | val selectedElements = filteredPairs.map(_._1)
5 | selectedElements
6 | }
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Hello World N Times/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(n: Int) = println("Hello World\n" * n)
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Hello World/Solution.scala:
--------------------------------------------------------------------------------
1 | def f() = println("Hello World")
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Lambda Calculus - Reductions #1/Solution.txt:
--------------------------------------------------------------------------------
1 | y
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Lambda Calculus - Reductions #2/Solution.txt:
--------------------------------------------------------------------------------
1 | w
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/List Length/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(arr: List[Int]): Int = arr.map(_ => 1).sum
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/List Replication/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(num: Int, arr: List[Int]): List[Int] = arr.flatMap(List.fill(num)(_))
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Reverse a List/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(arr: List[Int]): List[Int] =
2 | (for (i <- arr.length - 1 to 0 by -1) yield arr(i)).toList
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Solve Me First FP/Solution.scala:
--------------------------------------------------------------------------------
1 | object Solution {
2 | def main(args Array[String]) {
3 | println(io.Source.stdin.getLines().take(2).map(_.toInt).sum)
4 | }
5 | }
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Sum of Odd Elements/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(arr: List[Int]): Int = arr.filter(_ % 2 != 0).sum
--------------------------------------------------------------------------------
/HackerRank1/Functional Programming/Introduction/Update List/Solution.scala:
--------------------------------------------------------------------------------
1 | def f(arr: List[Int]): List[Int] = arr.map(Math.abs)
--------------------------------------------------------------------------------
/HackerRank1/Interview Preparation Kit/Arrays/Arrays Left Rotation/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner in = new Scanner(System.in);
7 | int n = in.nextInt();
8 | int k = in.nextInt();
9 | int a[] = new int[n];
10 | for (int i = 0; i < n; i++) {
11 | int idx = (i + n - k) % n;
12 | a[idx] = in.nextInt();
13 | }
14 | for (int i = 0; i < n; i++) {
15 | System.out.print(a[i] + " ");
16 | }
17 | in.close();
18 | }
19 | }
--------------------------------------------------------------------------------
/HackerRank1/Interview Preparation Kit/Sorting/Sorting Comparator/Solution.java:
--------------------------------------------------------------------------------
1 | class Checker implements Comparator {
2 |
3 | @Override
4 | public int compare(Player p1, Player p2) {
5 | if (p1.score == p2.score) {
6 | return p1.name.compareTo(p2.name);
7 | } else {
8 | return p2.score - p1.score;
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/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 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Advanced/Java Singleton Pattern/Solution.java:
--------------------------------------------------------------------------------
1 | class Singleton {
2 | public String str;
3 |
4 | private Singleton() {}
5 |
6 | private static Singleton instance;
7 |
8 | public static Singleton getSingleInstance() {
9 | if (instance == null) {
10 | instance = new Singleton();
11 | }
12 | return instance;
13 | }
14 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/BigNumber/Java BigInteger/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.math.BigInteger;
3 |
4 | public class Solution {
5 |
6 | public static void main(String[] args) {
7 | Scanner scan = new Scanner(System.in);
8 | BigInteger x = new BigInteger(scan.next());
9 | BigInteger y = new BigInteger(scan.next());
10 | System.out.println(x.add(y));
11 | System.out.println(x.multiply(y));
12 | }
13 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/BigNumber/Java Primality Test/Solution.java:
--------------------------------------------------------------------------------
1 | import java.math.*;
2 | import java.util.*;
3 |
4 | public class Solution {
5 |
6 | public static void main(String[] args) {
7 | Scanner sc = new Scanner(System.in);
8 | BigInteger n = sc.nextBigInteger();
9 | sc.close();
10 | System.out.println(n.isProbablePrime(10) ? "prime" : "not prime");
11 | }
12 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Data Structures/Java 1D Array/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner scan = new Scanner(System.in);
7 | int n = scan.nextInt();
8 |
9 | int[] a = new int[n];
10 |
11 | for (int i = 0; i < n; i++) {
12 | a[i] = scan.nextInt();
13 | }
14 | scan.close();
15 |
16 | // Prints each sequential element in array a
17 | for (int i = 0; i < a.length; i++) {
18 | System.out.println(a[i]);
19 | }
20 | }
21 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Exception Handling/Java Exception Handling/Solution.java:
--------------------------------------------------------------------------------
1 | class MyCalculator {
2 | long power(int n, int p) throws Exception {
3 | if (n < 0 || p < 0) {
4 | throw new Exception("n or p should not be negative.");
5 | } else if (n == 0 && p == 0) {
6 | throw new Exception("n and p should not be zero.");
7 | }
8 | return (long) Math.pow(n, p);
9 | }
10 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/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 | Scanner sc = new Scanner(System.in);
7 | int n = 0;
8 | while (sc.hasNext()) {
9 | System.out.println(++n + " " + sc.nextLine());
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Introduction/Java If-Else/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner sc = new Scanner(System.in);
7 | int n = sc.nextInt();
8 | String ans = "";
9 | if (n % 2 == 1 || (n >= 6 && n <= 20)) {
10 | ans = "Weird";
11 | } else {
12 | ans = "Not Weird";
13 | }
14 | System.out.println(ans);
15 | }
16 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Introduction/Java Loops I/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 | import java.util.stream.IntStream;
3 |
4 | public class Solution {
5 | private static final Scanner scanner = new Scanner(System.in);
6 |
7 | public static void main(String[] args) {
8 | int n = scanner.nextInt();
9 | IntStream.rangeClosed(1, 10)
10 | .mapToObj(i -> String.format("%d x %d = %d", n, i, n * i))
11 | .forEach(System.out::println);
12 | scanner.close();
13 | }
14 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Introduction/Java Output Formatting/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner sc = new Scanner(System.in);
7 | System.out.println("================================");
8 | for (int i = 0; i < 3; i++) {
9 | String s = sc.next();
10 | int x = sc.nextInt();
11 | System.out.printf("%-15s%03d%n", s, x);
12 | }
13 | System.out.println("================================");
14 | }
15 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Introduction/Java Static Initializer Block/Solution.java:
--------------------------------------------------------------------------------
1 | static Scanner sc = new Scanner(System.in);
2 | static int B = sc.nextInt();
3 | static int H = sc.nextInt();
4 | static boolean flag = B > 0 && H > 0;
5 |
6 | static {
7 | if (!flag)
8 | System.out.println("java.lang.Exception: Breadth and height must be positive");
9 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Introduction/Java Stdin and Stdout I/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner sc = new Scanner(System.in);
7 | while (sc.hasNextInt()) {
8 | System.out.println(sc.nextInt());
9 | }
10 | }
11 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Introduction/Java Stdin and Stdout II/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner sc = new Scanner(System.in);
7 | int i = sc.nextInt();
8 | double d = sc.nextDouble();
9 | sc.nextLine();
10 | String s = sc.nextLine();
11 |
12 | System.out.println("String: " + s);
13 | System.out.println("Double: " + d);
14 | System.out.println("Int: " + i);
15 | }
16 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Introduction/Welcome to Java!/Solution.java:
--------------------------------------------------------------------------------
1 | public class Solution {
2 |
3 | public static void main(String[] args) {
4 | System.out.println("Hello, World.");
5 | System.out.println("Hello, Java.");
6 | }
7 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Strings/Java Regex/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner in = new Scanner(System.in);
7 | while (in.hasNext()) {
8 | String IP = in.next();
9 | System.out.println(IP.matches(new MyRegex().pattern));
10 | }
11 | }
12 | }
13 |
14 | class MyRegex {
15 | String ipPart = "([01]?\\d{1,2}|2[0-4]\\d|25[0-5])";
16 | String pattern = "(" + ipPart + "\\.){3}" + ipPart;
17 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Strings/Java String Reverse/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner sc = new Scanner(System.in);
7 | String str = sc.next();
8 | String reversed = new StringBuilder(str).reverse().toString();
9 | System.out.println(str.equals(reversed) ? "Yes" : "No");
10 | }
11 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Strings/Java String Tokens/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner scan = new Scanner(System.in);
7 | String str = scan.nextLine().trim();
8 | scan.close();
9 |
10 | String[] tokens = str.split("[^\\p{Alpha}]+");
11 |
12 | int length = (str.isEmpty()) ? 0 : tokens.length;
13 | System.out.println(length);
14 |
15 | for (String token : tokens) {
16 | System.out.println(token);
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/HackerRank1/Java/Strings/Java Substring/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner in = new Scanner(System.in);
7 | String str = in.next();
8 | int start = in.nextInt();
9 | int end = in.nextInt();
10 | System.out.println(str.substring(start, end));
11 | }
12 | }
--------------------------------------------------------------------------------
/HackerRank1/Python/Basic Data Types/Find the Runner-Up Score!/Solution.py:
--------------------------------------------------------------------------------
1 | input()
2 | array = map(int, input().split())
3 | print(sorted(list(set(array)))[-2])
--------------------------------------------------------------------------------
/HackerRank1/Python/Basic Data Types/Finding the percentage/Solution.py:
--------------------------------------------------------------------------------
1 | n = int(input())
2 | student_marks = {}
3 | for _ in range(n):
4 | name, *line = input().split()
5 | scores = list(map(float, line))
6 | student_marks[name] = scores
7 |
8 | query_name = input()
9 | query_scores = student_marks[query_name]
10 | avg = sum(query_scores) / 3.0
11 | print("%.2f" % avg)
--------------------------------------------------------------------------------
/HackerRank1/Python/Basic Data Types/List Comprehensions/Solution.py:
--------------------------------------------------------------------------------
1 | x, y, z, n = (int(input()) for _ in range(4))
2 | print ([[a, b, c] for a in range(x + 1) for b in range(y + 1) for c in range(z + 1) if a + b + c != n])
--------------------------------------------------------------------------------
/HackerRank1/Python/Basic Data Types/Nested Lists/Solution.py:
--------------------------------------------------------------------------------
1 | grade_sheet = []
2 | for _ in range(int(input())):
3 | name = input()
4 | score = float(input())
5 | grade_sheet.append([name, score])
6 |
7 | second_lowest = sorted(list(set([grades for name, grades in grade_sheet])))[1]
8 | print('\n'.join([a for a, b in sorted(grade_sheet) if b == second_lowest]))
--------------------------------------------------------------------------------
/HackerRank1/Python/Basic Data Types/Tuples/Solution.py:
--------------------------------------------------------------------------------
1 | input()
2 | integer_list = map(int, input().split())
3 | print(hash(tuple(integer_list)))
--------------------------------------------------------------------------------
/HackerRank1/Python/Built-Ins/Any or All/Solution.py:
--------------------------------------------------------------------------------
1 | _ = input()
2 | n = input().split()
3 | print(all([int(i) > 0 for i in n]) and any([j == j[::-1] for j in n]))
--------------------------------------------------------------------------------
/HackerRank1/Python/Built-Ins/Athlete Sort/Solution.py:
--------------------------------------------------------------------------------
1 | n, m = map(int, input().split())
2 | rows = [input() for _ in range(n)]
3 | k = int(input())
4 |
5 | for row in sorted(rows, key=lambda row: int(row.split()[k])):
6 | print(row)
--------------------------------------------------------------------------------
/HackerRank1/Python/Built-Ins/Input()/Solution.py:
--------------------------------------------------------------------------------
1 | x, k = map(int, input().split())
2 | print(eval(input()) == k)
--------------------------------------------------------------------------------
/HackerRank1/Python/Built-Ins/Python Evaluation/Solution.py:
--------------------------------------------------------------------------------
1 | eval(input())
--------------------------------------------------------------------------------
/HackerRank1/Python/Built-Ins/Zipped!/Solution.py:
--------------------------------------------------------------------------------
1 | n, x = map(int, input().split())
2 |
3 | sheet = []
4 | for _ in range(x):
5 | sheet.append(map(float, input().split()))
6 |
7 | for i in zip(*sheet):
8 | print(sum(i) / len(i))
--------------------------------------------------------------------------------
/HackerRank1/Python/Built-Ins/ginortS/Solution.py:
--------------------------------------------------------------------------------
1 | print(*sorted(input(), key=lambda c: (c.isdigit() - c.islower(), c in '02468', c)), sep='')
--------------------------------------------------------------------------------
/HackerRank1/Python/Closures and Decorators/Decorators 2 - Name Directory/Solution.py:
--------------------------------------------------------------------------------
1 | import operator
2 |
3 |
4 | def person_lister(f):
5 | def inner(people):
6 | return map(f, sorted(people, key=lambda x: int(x[2])))
7 |
8 | return inner
9 |
10 |
11 | @person_lister
12 | def name_format(person):
13 | return ('Mr. ' if person[3] == 'M' else 'Ms. ') + person[0] + ' ' + person[1]
14 |
15 |
16 | if __name__ == '__main__':
17 | people = [input().split() for i in range(int(input()))]
18 | print(*name_format(people), sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Closures and Decorators/Standardize Mobile Number Using Decorators/Solution.py:
--------------------------------------------------------------------------------
1 | def wrapper(f):
2 | def fun(l):
3 | f(['+91 ' + c[-10:-5] + ' ' + c[-5:] for c in l])
4 |
5 | return fun
6 |
7 |
8 | @wrapper
9 | def sort_phone(l):
10 | print(*sorted(l), sep='\n')
11 |
12 |
13 | if __name__ == '__main__':
14 | l = [input() for _ in range(int(input()))]
15 | sort_phone(l)
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/Collections.Counter()/Solution.py:
--------------------------------------------------------------------------------
1 | from collections import Counter
2 |
3 | num_shoes = int(input())
4 | shoe_sizes = Counter(map(int, input().split()))
5 | num_customers = int(input())
6 |
7 | cost = 0
8 | for _ in range(num_customers):
9 | size, price = map(int, input().split())
10 | if shoe_sizes[size]:
11 | cost += price
12 | shoe_sizes[size] -= 1
13 |
14 | print(cost)
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/Collections.OrderedDict()/Solution.py:
--------------------------------------------------------------------------------
1 | from collections import OrderedDict
2 |
3 | order = OrderedDict()
4 | for _ in range(int(input())):
5 | item, space, price = input().rpartition(' ')
6 | order[item] = order.get(item, 0) + int(price)
7 | for item, price in order.items():
8 | print(item, price)
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/Collections.deque()/Solution.py:
--------------------------------------------------------------------------------
1 | from collections import deque
2 |
3 | d = deque()
4 | for i in range(int(input())):
5 | command = input().split()
6 | if command[0] == 'append':
7 | d.append(command[1])
8 | elif command[0] == 'appendleft':
9 | d.appendleft(command[1])
10 | elif command[0] == 'pop':
11 | d.pop()
12 | else:
13 | d.popleft()
14 | print(' '.join(d))
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/Collections.namedtuple()/Solution.py:
--------------------------------------------------------------------------------
1 | from collections import namedtuple
2 |
3 | n = int(input())
4 | fields = input().split()
5 |
6 | total_marks = 0
7 | for _ in range(n):
8 | students = namedtuple('student', fields)
9 | MARKS, CLASS, NAME, ID = input().split()
10 | student = students(MARKS, CLASS, NAME, ID)
11 | total_marks += int(student.MARKS)
12 | print('{:.2f}'.format(total_marks / n))
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/Company Logo/Solution.py:
--------------------------------------------------------------------------------
1 | import collections
2 |
3 | s = sorted(input().strip())
4 | s_counter = collections.Counter(s).most_common()
5 |
6 | s_counter = sorted(s_counter, key=lambda x: (x[1] * -1, x[0]))
7 | for i in range(0, 3):
8 | print(s_counter[i][0], s_counter[i][1])
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/DefaultDict Tutorial/Solution.py:
--------------------------------------------------------------------------------
1 | from collections import defaultdict
2 |
3 | d = defaultdict(list)
4 | n, m = map(int, input().split())
5 |
6 | for i in range(n):
7 | d[input()].append(str(i + 1))
8 | for j in range(m):
9 | print(' '.join(d[input()]) or -1)
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/Piling Up!/Solution.py:
--------------------------------------------------------------------------------
1 | for t in range(int(input())):
2 | l = int(input())
3 | sides = list(map(int, input().split()))
4 | i = 0
5 | while i < l - 1 and sides[i] >= sides[i + 1]:
6 | i += 1
7 | while i < l - 1 and sides[i] <= sides[i + 1]:
8 | i += 1
9 | print('Yes' if i == l - 1 else 'No')
--------------------------------------------------------------------------------
/HackerRank1/Python/Collections/Word Order/Solution.py:
--------------------------------------------------------------------------------
1 | from collections import OrderedDict
2 |
3 | dict = OrderedDict()
4 |
5 | for _ in range(int(input())):
6 | key = input()
7 | dict[key] = dict.get(key, 0) + 1
8 |
9 | print(len(dict))
10 | print(*dict.values())
--------------------------------------------------------------------------------
/HackerRank1/Python/Date and Time/Calendar Module/Solution.py:
--------------------------------------------------------------------------------
1 | import datetime
2 | import calendar
3 |
4 | m, d, y = map(int, input().split())
5 | input_date = datetime.date(y, m, d)
6 | print(calendar.day_name[input_date.weekday()].upper())
--------------------------------------------------------------------------------
/HackerRank1/Python/Date and Time/Time Delta/Solution.py:
--------------------------------------------------------------------------------
1 | import datetime
2 |
3 | for t in range(int(input())):
4 | timestamp1 = input().strip()
5 | timestamp2 = input().strip()
6 | time_format = '%a %d %b %Y %H:%M:%S %z'
7 | time_second1 = datetime.datetime.strptime(timestamp1, time_format)
8 | time_second2 = datetime.datetime.strptime(timestamp2, time_format)
9 | print(int(abs((time_second1 - time_second2).total_seconds())))
--------------------------------------------------------------------------------
/HackerRank1/Python/Debugging/Words Score/Solution.py:
--------------------------------------------------------------------------------
1 | def is_vowel(letter):
2 | return letter in ['a', 'e', 'i', 'o', 'u', 'y']
3 |
4 |
5 | def score_words(words):
6 | score = 0
7 | for word in words:
8 | num_vowels = 0
9 | for letter in word:
10 | if is_vowel(letter):
11 | num_vowels += 1
12 | if num_vowels % 2 == 0:
13 | score += 2
14 | else:
15 | score += 1
16 | return score
17 |
18 |
19 | n = int(input())
20 | words = input().split()
21 | print(score_words(words))
--------------------------------------------------------------------------------
/HackerRank1/Python/Errors and Exceptions/Exceptions/Solution.py:
--------------------------------------------------------------------------------
1 | for _ in range(int(input())):
2 | a, b = input().split()
3 | try:
4 | print(int(a) // int(b))
5 | except Exception as e:
6 | print('Error Code: ' + str(e))
--------------------------------------------------------------------------------
/HackerRank1/Python/Errors and Exceptions/Incorrect Regex/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | for _ in range(int(input())):
4 | try:
5 | re.compile(input())
6 | print(True)
7 | except Exception as e:
8 | print(False)
--------------------------------------------------------------------------------
/HackerRank1/Python/Introduction/Arithmetic Operators/Solution.py:
--------------------------------------------------------------------------------
1 | a = int(input())
2 | b = int(input())
3 |
4 | print('{0} \n{1} \n{2}'.format((a + b), (a - b), (a * b)))
--------------------------------------------------------------------------------
/HackerRank1/Python/Introduction/Loops/Solution.py:
--------------------------------------------------------------------------------
1 | n = int(input())
2 |
3 | [print(i ** 2) for i in range(n)]
--------------------------------------------------------------------------------
/HackerRank1/Python/Introduction/Print Function/Solution.py:
--------------------------------------------------------------------------------
1 | n = int(input())
2 | print(*range(1, n + 1), sep='')
--------------------------------------------------------------------------------
/HackerRank1/Python/Introduction/Python Division/Solution.py:
--------------------------------------------------------------------------------
1 | a = int(input())
2 | b = int(input())
3 |
4 | print("{0} \n{1}".format(a // b, a / b))
--------------------------------------------------------------------------------
/HackerRank1/Python/Introduction/Python If-Else/Solution.py:
--------------------------------------------------------------------------------
1 | n = int(input())
2 |
3 | if n % 2 == 1:
4 | print("Weird")
5 | elif n % 2 == 0 and 2 <= n <= 5:
6 | print("Not Weird")
7 | elif n % 2 == 0 and 6 <= n <= 20:
8 | print("Weird")
9 | else:
10 | print("Not Weird")
--------------------------------------------------------------------------------
/HackerRank1/Python/Introduction/Say Hello, World! With Python/Solution.py:
--------------------------------------------------------------------------------
1 | print("Hello, World!")
--------------------------------------------------------------------------------
/HackerRank1/Python/Introduction/Write a function/Solution.py:
--------------------------------------------------------------------------------
1 | def is_leap(year):
2 | return ((year % 400 == 0) or (year % 4 == 0 and year % 100 != 0))
3 |
4 |
5 | year = int(input())
6 | print(is_leap(year))
--------------------------------------------------------------------------------
/HackerRank1/Python/Itertools/Compress the String!/Solution.py:
--------------------------------------------------------------------------------
1 | from itertools import groupby
2 |
3 | for key, group in groupby(input()):
4 | print((len(list(group)), int(key)), end=' ')
--------------------------------------------------------------------------------
/HackerRank1/Python/Itertools/Iterables and Iterators/Solution.py:
--------------------------------------------------------------------------------
1 | from itertools import combinations
2 |
3 | n = int(input())
4 | array = input().split()
5 | k = int(input())
6 |
7 | comb_list = list(combinations(array, k))
8 | a_list = [e for e in comb_list if 'a' in e]
9 | print(len(a_list) / len(comb_list))
--------------------------------------------------------------------------------
/HackerRank1/Python/Itertools/Maximize It!/Solution.py:
--------------------------------------------------------------------------------
1 | from itertools import product
2 |
3 | k, m = map(int, input().split())
4 |
5 | array = []
6 | for _ in range(k):
7 | array.append(list(map(int, input().split()))[1:])
8 |
9 | result = 0
10 | for combination in product(*array):
11 | result = max(sum([x * x for x in combination]) % m, result)
12 | print(result)
--------------------------------------------------------------------------------
/HackerRank1/Python/Itertools/itertools.combinations()/Solution.py:
--------------------------------------------------------------------------------
1 | import itertools
2 |
3 | string, combination_size = input().split()
4 | for length in range(1, int(combination_size) + 1):
5 | for combination in itertools.combinations(sorted(string), length):
6 | print(''.join(combination))
--------------------------------------------------------------------------------
/HackerRank1/Python/Itertools/itertools.combinations_with_replacement()/Solution.py:
--------------------------------------------------------------------------------
1 | import itertools
2 |
3 | string, combination_size = input().split()
4 | for combination in itertools.combinations_with_replacement(sorted(string), int(combination_size)):
5 | print(''.join(combination))
--------------------------------------------------------------------------------
/HackerRank1/Python/Itertools/itertools.permutations()/Solution.py:
--------------------------------------------------------------------------------
1 | import itertools
2 |
3 | string, permutation_size = input().split()
4 | for permutation in itertools.permutations(sorted(string), int(permutation_size)):
5 | print(''.join(permutation))
--------------------------------------------------------------------------------
/HackerRank1/Python/Itertools/itertools.product()/Solution.py:
--------------------------------------------------------------------------------
1 | import itertools
2 |
3 | A = [int(x) for x in input().split()]
4 | B = [int(y) for y in input().split()]
5 |
6 | print(*itertools.product(A, B))
--------------------------------------------------------------------------------
/HackerRank1/Python/Math/Find Angle MBC/Solution.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackerRank1/Python/Math/Find Angle MBC/Solution.py
--------------------------------------------------------------------------------
/HackerRank1/Python/Math/Integers Come In All Sizes/Solution.py:
--------------------------------------------------------------------------------
1 | a, b, c, d = [int(input()) for _ in range(4)]
2 | print(a ** b + c ** d)
--------------------------------------------------------------------------------
/HackerRank1/Python/Math/Mod Divmod/Solution.py:
--------------------------------------------------------------------------------
1 | d = divmod(int(input()), int(input()))
2 | print(*d, d, sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Math/Polar Coordinates/Solution.py:
--------------------------------------------------------------------------------
1 | import cmath
2 |
3 | z = complex(input())
4 | print(*cmath.polar(z), sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Math/Power - Mod Power/Solution.py:
--------------------------------------------------------------------------------
1 | a, b, m = [int(input()) for _ in range(3)]
2 | print(pow(a, b), pow(a, b, m), sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Math/Triangle Quest 2/Solution.py:
--------------------------------------------------------------------------------
1 | for i in range(1, int(input()) + 1): # More than 2 lines will result in 0 score. Do not leave a blank line also
2 | print((10 ** i - 1) ** 2 // 81)
--------------------------------------------------------------------------------
/HackerRank1/Python/Math/Triangle Quest/Solution.py:
--------------------------------------------------------------------------------
1 | for i in range(1, int(input())): # More than 2 lines will result in 0 score. Do not leave a blank line also
2 | print(i * ((pow(10, i) - 1) // 9))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Array Mathematics/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | n, m = map(int, input().split())
4 | a, b = (np.array([input().split() for _ in range(n)], dtype=int) for _ in range(2))
5 | print(a + b, a - b, a * b, a // b, a % b, a ** b, sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Arrays/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy
2 |
3 |
4 | def arrays(arr):
5 | return (numpy.array(arr[::-1], float))
6 |
7 |
8 | arr = input().strip().split(' ')
9 | result = arrays(arr)
10 | print(result)
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Concatenate/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | a, b, c = map(int, input().split())
4 | A = np.array([input().split() for _ in range(a)], int)
5 | B = np.array([input().split() for _ in range(b)], int)
6 | print(np.concatenate((A, B), axis=0))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Dot and Cross/Solution.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))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Eye and Identity/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy
2 |
3 | numpy.set_printoptions(sign=' ')
4 | print(numpy.eye(*map(int, input().split())))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Floor, Ceil and Rint/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | np.set_printoptions(sign=' ')
4 |
5 | a = np.array(input().split(), float)
6 | print(*(f(a) for f in [np.floor, np.ceil, np.rint]), sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Inner and Outer/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | A = np.array(input().split(), int)
4 | B = np.array(input().split(), int)
5 | print(np.inner(A, B), np.outer(A, B), sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Linear Algebra/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | np.set_printoptions(legacy='1.13')
4 |
5 | n = int(input())
6 | array = np.array([input().split() for _ in range(n)], float)
7 | print(np.linalg.det(array))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Mean, Var, and Std/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | np.set_printoptions(legacy='1.13')
4 |
5 | n, m = map(int, input().split())
6 | array = np.array([input().split() for _ in range(n)], int)
7 | print(np.mean(array, axis=1), np.var(array, axis=0), np.std(array), sep = '\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Min and Max/Solution.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.max(numpy.min(A, axis=1), axis=0))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Polynomials/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | poly = [float(x) for x in input().split()]
4 | x = float(input())
5 | print(np.polyval(poly, x))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Shape and Reshape/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | print(np.array(input().split(), int).reshape(3, 3))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Sum and Prod/Solution.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))
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Transpose and Flatten/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | n, m = map(int, input().split())
4 | array = np.array([input().strip().split() for _ in range(n)], int)
5 | print(array.transpose())
6 | print(array.flatten())
--------------------------------------------------------------------------------
/HackerRank1/Python/Numpy/Zeros and Ones/Solution.py:
--------------------------------------------------------------------------------
1 | import numpy
2 |
3 | nums = tuple(map(int, input().split()))
4 | print(numpy.zeros(nums, dtype=numpy.int))
5 | print(numpy.ones(nums, dtype=numpy.int))
--------------------------------------------------------------------------------
/HackerRank1/Python/Python Functionals/Map and Lambda Function/Solution.py:
--------------------------------------------------------------------------------
1 | cube = lambda x: x ** 3
2 |
3 |
4 | def fibonacci(n):
5 | a, b, c = 0, 1, 1
6 | for _ in range(n):
7 | yield a
8 | a, b = b, a + b
9 |
10 |
11 | if __name__ == '__main__':
12 | n = int(input())
13 | print(list(map(cube, fibonacci(n))))
--------------------------------------------------------------------------------
/HackerRank1/Python/Python Functionals/Reduce Function/Solution.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))
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)
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Detect Floating Point Number/Solution.py:
--------------------------------------------------------------------------------
1 | from re import match, compile
2 |
3 | pattern = compile('^[-+]?[0-9]*\.[0-9]+$')
4 | for _ in range(int(input())):
5 | print(bool(pattern.match(input())))
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Detect HTML Tags, Attributes and Attribute Values/Solution.py:
--------------------------------------------------------------------------------
1 | from html.parser import HTMLParser
2 |
3 |
4 | class MyHTMLParser(HTMLParser):
5 | def handle_starttag(self, tag, attrs):
6 | print(tag)
7 | [print('-> {} > {}'.format(*attr)) for attr in attrs]
8 |
9 |
10 | html = '\n'.join([input() for _ in range(int(input()))])
11 | parser = MyHTMLParser()
12 | parser.feed(html)
13 | parser.close()
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Group(), Groups() & Groupdict()/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | m = re.search(r'([a-zA-Z0-9])\1', input().strip())
4 | print(m.group(1) if m else -1)
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Hex Color Code/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | for _ in range(int(input())):
4 | matches = re.findall(r':?.(#[0-9a-fA-F]{6}|#[0-9a-fA-F]{3})', input())
5 | if matches:
6 | print(*matches, sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Matrix Script/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | n, m = map(int, input().split())
4 | a, b = [], ''
5 | for _ in range(n):
6 | a.append(input())
7 |
8 | for z in zip(*a):
9 | b += ''.join(z)
10 |
11 | print(re.sub(r'(?<=\w)([^\w]+)(?=\w)', ' ', b))
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Re.findall() & Re.finditer()/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | vowels = 'aeiou'
4 | consonants = 'qwrtypsdfghjklzxcvbnm'
5 | match = re.findall(r'(?<=[' + consonants + '])([' + vowels + ']{2,})(?=[' + consonants + '])', input(), flags=re.I)
6 | print('\n'.join(match or ['-1']))
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Re.split()/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | regex_pattern = r'[.,]+'
4 |
5 | print('\n'.join(re.split(regex_pattern, input())))
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Re.start() & Re.end()/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | string = input()
4 | substring = input()
5 |
6 | pattern = re.compile(substring)
7 | match = pattern.search(string)
8 | if not match: print('(-1, -1)')
9 | while match:
10 | print('({0}, {1})'.format(match.start(), match.end() - 1))
11 | match = pattern.search(string, match.start() + 1)
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Regex Substitution/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | for _ in range(int(input())):
4 | print(re.sub(r'(?<= )(&&|\|\|)(?= )', lambda x: 'and' if x.group() == '&&' else 'or', input()))
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Validating Credit Card Numbers/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | pattern = re.compile(
4 | r'^'
5 | r'(?!.*(\d)(-?\1){3})'
6 | r'[456]\d{3}'
7 | r'(?:-?\d{4}){3}'
8 | r'$')
9 | for _ in range(int(input().strip())):
10 | print('Valid' if pattern.search(input().strip()) else 'Invalid')
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Validating Postal Codes/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | P = input()
4 |
5 | regex_integer_in_range = r'^[1-9][\d]{5}$' # Do not delete 'r'.
6 | regex_alternating_repetitive_digit_pair = r'(\d)(?=\d\1)' # Do not delete 'r'.
7 |
8 | print (bool(re.match(regex_integer_in_range, P))
9 | and len(re.findall(regex_alternating_repetitive_digit_pair, P)) < 2)
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Validating Roman Numerals/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | regex_pattern = r'M{0,3}(C[MD]|D?C{0,3})(X[CL]|L?X{0,3})(I[VX]|V?I{0,3})$'
4 |
5 | print(str(bool(re.match(regex_pattern, input()))))
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Validating UID/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | for _ in range(int(input())):
4 | u = ''.join(sorted(input()))
5 | try:
6 | assert re.search(r'[A-Z]{2}', u)
7 | assert re.search(r'\d\d\d', u)
8 | assert not re.search(r'[^a-zA-Z0-9]', u)
9 | assert not re.search(r'(.)\1', u)
10 | assert len(u) == 10
11 | except:
12 | print('Invalid')
13 | else:
14 | print('Valid')
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Validating and Parsing Email Addresses/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | pattern = r'^<[A-Za-z](\w|-|\.|_)+@[A-Za-z]+\.[A-Za-z]{1,3}>$'
4 | for _ in range(int(input())):
5 | name, email = input().split(' ')
6 | if re.match(pattern, email):
7 | print(name, email)
--------------------------------------------------------------------------------
/HackerRank1/Python/Regex and Parsing/Validating phone numbers/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 | [print('YES' if re.match(r'[789]\d{9}$', input()) else 'NO') for _ in range(int(input()))]
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Check Strict Superset/Solution.py:
--------------------------------------------------------------------------------
1 | A = set(input().split())
2 |
3 | for _ in range(int(input())):
4 | if not A.issuperset(set(input().split())):
5 | print(False)
6 | break
7 | else:
8 | print(True)
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Check Subset/Solution.py:
--------------------------------------------------------------------------------
1 | for _ in range(int(input())):
2 | a, A = input(), set(input().split())
3 | b, B = input(), set(input().split())
4 |
5 | print(A.issubset(B))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Introduction to Sets/Solution.py:
--------------------------------------------------------------------------------
1 | def average(array):
2 | distinct_heights = set(array)
3 | return sum(distinct_heights) / len(distinct_heights)
4 |
5 |
6 | if __name__ == '__main__':
7 | n = int(input())
8 | arr = list(map(int, input().split()))
9 | result = average(arr)
10 | print(result)
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/No Idea!/Solution.py:
--------------------------------------------------------------------------------
1 | n, m = input().split()
2 |
3 | array = input().split()
4 | A = set(input().split())
5 | B = set(input().split())
6 |
7 | print(sum([(i in A) - (i in B) for i in array]))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Set .add()/Solution.py:
--------------------------------------------------------------------------------
1 | stamps = set()
2 | for _ in range(int(input())):
3 | stamps.add(input())
4 | print(len(stamps))
5 |
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Set .difference() Operation/Solution.py:
--------------------------------------------------------------------------------
1 | _, en_subscribers = input(), set(map(int, input().split()))
2 | _, fr_subscribers = input(), set(map(int, input().split()))
3 | print(len(en_subscribers.difference(fr_subscribers)))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Set .discard(), .remove() & .pop()/Solution.py:
--------------------------------------------------------------------------------
1 | n = input()
2 | elements = set(map(int, input().split()))
3 |
4 | for _ in range(int(input())):
5 | command = input().split()
6 | operation = command[0]
7 | args = command[1:]
8 |
9 | if operation != 'pop':
10 | operation += '(' + ','.join(args) + ')'
11 | eval('elements.' + operation)
12 | else:
13 | elements.pop()
14 | print(sum(elements))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Set .intersection() Operation/Solution.py:
--------------------------------------------------------------------------------
1 | _, en_subscribers = input(), set(map(int, input().split()))
2 | _, fr_subscribers = input(), set(map(int, input().split()))
3 | print(len(en_subscribers.intersection(fr_subscribers)))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Set .symmetric_difference() Operation/Solution.py:
--------------------------------------------------------------------------------
1 | _, en_subscribers = input(), set(map(int, input().split()))
2 | _, fr_subscribers = input(), set(map(int, input().split()))
3 | print(len(en_subscribers.symmetric_difference(fr_subscribers)))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Set .union() Operation/Solution.py:
--------------------------------------------------------------------------------
1 | _, en_subscribers = input(), set(map(int, input().split()))
2 | _, fr_subscribers = input(), set(map(int, input().split()))
3 | print(len(en_subscribers.union(fr_subscribers)))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Set Mutations/Solution.py:
--------------------------------------------------------------------------------
1 | N = input()
2 | A = set(map(int, input().split()))
3 |
4 | for _ in range(int(input())):
5 | command = input().split()[0]
6 | elements = input().split()
7 | command += '([' + ','.join(elements) + '])'
8 | eval('A.' + command)
9 | print(sum(A))
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/Symmetric Difference/Solution.py:
--------------------------------------------------------------------------------
1 | m = input()
2 | a = set(map(int, input().split()))
3 | n = input()
4 | b = set(map(int, input().split()))
5 |
6 | print(*sorted(a.symmetric_difference(b)), sep='\n')
--------------------------------------------------------------------------------
/HackerRank1/Python/Sets/The Captain's Room/Solution.py:
--------------------------------------------------------------------------------
1 | K = int(input())
2 |
3 | room_list = list(map(int, input().split()))
4 | room_set = set(room_list)
5 | sum_room_list = sum(room_list)
6 | sum_room_set = sum(room_set)
7 | diff = sum_room_set * K - sum_room_list
8 |
9 | print(diff // (K - 1))
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/Capitalize!/Solution.py:
--------------------------------------------------------------------------------
1 | def capitalize(string):
2 | full_name = string.split(' ')
3 | return ' '.join((word.capitalize() for word in full_name))
4 |
5 |
6 | if __name__ == '__main__':
7 | string = input()
8 | capitalized_string = capitalize(string)
9 | print(capitalized_string)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/Designer Door Mat/Solution.py:
--------------------------------------------------------------------------------
1 | n, m = map(int, input().split())
2 | pattern = [('.|.' * (2 * i + 1)).center(m, '-') for i in range(n // 2)]
3 | print('\n'.join(pattern + ['WELCOME'.center(m, '-')] + pattern[::-1]))
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/Find a string/Solution.py:
--------------------------------------------------------------------------------
1 | import re
2 |
3 |
4 | def count_substring(string, sub_string):
5 | match = re.findall('(?=' + sub_string + ')', string)
6 | return len(match)
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)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/Merge the Tools!/Solution.py:
--------------------------------------------------------------------------------
1 | from collections import OrderedDict
2 |
3 |
4 | def merge_the_tools(string, k):
5 | for i in range(0, len(string), k):
6 | print(''.join(OrderedDict.fromkeys(string[i:i + k])))
7 |
8 |
9 | if __name__ == '__main__':
10 | string, k = input(), int(input())
11 | merge_the_tools(string, k)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/Mutations/Solution.py:
--------------------------------------------------------------------------------
1 | def mutate_string(string, position, character):
2 | return string[:position] + character + string[position + 1:]
3 |
4 |
5 | if __name__ == '__main__':
6 | s = input()
7 | i, c = input().split()
8 | s_new = mutate_string(s, int(i), c)
9 | print(s_new)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/String Formatting/Solution.py:
--------------------------------------------------------------------------------
1 | def print_formatted(number):
2 | width = len("{0:b}".format(number))
3 | for i in range(1, number + 1):
4 | print("{0:{width}d} {0:{width}o} {0:{width}X} {0:{width}b}".format(i, width=width))
5 |
6 |
7 | if __name__ == '__main__':
8 | n = int(input())
9 | print_formatted(n)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/String Split and Join/Solution.py:
--------------------------------------------------------------------------------
1 | def split_and_join(line):
2 | return "-".join(line.split(" "))
3 |
4 |
5 | if __name__ == '__main__':
6 | line = input()
7 | result = split_and_join(line)
8 | print(result)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/String Validators/Solution.py:
--------------------------------------------------------------------------------
1 | if __name__ == '__main__':
2 | str = input()
3 | print(any(c.isalnum() for c in str))
4 | print(any(c.isalpha() for c in str))
5 | print(any(c.isdigit() for c in str))
6 | print(any(c.islower() for c in str))
7 | print(any(c.isupper() for c in str))
8 |
9 | # for test in ('isalnum', 'isalpha', 'isdigit', 'islower', 'isupper'):
10 | # print(any(eval("c." + test + "()") for c in str))
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/Text Wrap/Solution.py:
--------------------------------------------------------------------------------
1 | import textwrap
2 |
3 |
4 | def wrap(string, max_width):
5 | return textwrap.fill(string, max_width)
6 |
7 |
8 | if __name__ == '__main__':
9 | string, max_width = input(), int(input())
10 | result = wrap(string, max_width)
11 | print(result)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/What's Your Name/Solution.py:
--------------------------------------------------------------------------------
1 | def print_full_name(first_name, last_name):
2 | print("Hello " + first_name + " " + last_name + "! You just delved into python.")
3 |
4 |
5 | if __name__ == '__main__':
6 | first_name = input()
7 | last_name = input()
8 | print_full_name(first_name, last_name)
--------------------------------------------------------------------------------
/HackerRank1/Python/Strings/sWAP cASE/Solution.py:
--------------------------------------------------------------------------------
1 | def swap_case(s):
2 | return s.swapcase()
3 |
4 |
5 | if __name__ == '__main__':
6 | s = input()
7 | result = swap_case(s)
8 | print(result)
--------------------------------------------------------------------------------
/HackerRank1/Python/XML/XML 1 - Find the Score/Solution.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import xml.etree.ElementTree as etree
3 |
4 |
5 | def get_attr_number(node):
6 | return len(node.attrib) + sum(get_attr_number(child) for child in node);
7 |
8 |
9 | if __name__ == '__main__':
10 | sys.stdin.readline()
11 | xml = sys.stdin.read()
12 | tree = etree.ElementTree(etree.fromstring(xml))
13 | root = tree.getroot()
14 | print(get_attr_number(root))
--------------------------------------------------------------------------------
/HackerRank1/Python/XML/XML2 - Find the Maximum Depth/Solution.py:
--------------------------------------------------------------------------------
1 | import xml.etree.ElementTree as etree
2 |
3 | maxdepth = 0
4 |
5 |
6 | def depth(elem, level):
7 | global maxdepth
8 | if (level == maxdepth):
9 | maxdepth += 1
10 |
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)
--------------------------------------------------------------------------------
/HackerRank1/SQL/Advanced Join/Placements/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT S.NAME
2 | FROM STUDENTS S,
3 | FRIENDS F,
4 | PACKAGES P1,
5 | PACKAGES P2
6 | WHERE S.ID = F.ID
7 | AND F.FRIEND_ID = P2.ID
8 | AND S.ID = P1.ID
9 | AND P1.SALARY < P2.SALARY
10 | ORDER BY P2.SALARY;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Advanced Join/Projects/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT START_DATE, MIN(END_DATE)
2 | FROM
3 | (SELECT START_DATE
4 | FROM PROJECTS
5 | WHERE START_DATE NOT IN
6 | (SELECT END_DATE
7 | FROM PROJECTS)) A,
8 | (SELECT END_DATE
9 | FROM PROJECTS
10 | WHERE END_DATE NOT IN
11 | (SELECT START_DATE
12 | FROM PROJECTS)) B
13 | WHERE START_DATE < END_DATE
14 | GROUP BY START_DATE
15 | ORDER BY (MIN(END_DATE) - START_DATE), START_DATE;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Advanced Join/Symmetric Pairs/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT X,
2 | Y
3 | FROM FUNCTIONS F1
4 | WHERE EXISTS
5 | (SELECT *
6 | FROM FUNCTIONS F2
7 | WHERE F2.Y = F1.X
8 | AND F2.X = F1.Y
9 | AND F2.X > F1.X)
10 | AND (X != Y)
11 | UNION
12 | SELECT X,
13 | Y
14 | FROM FUNCTIONS F1
15 | WHERE X = Y
16 | AND (
17 | (SELECT COUNT(*)
18 | FROM FUNCTIONS
19 | WHERE X = F1.X
20 | AND Y = F1.X) > 1)
21 | ORDER BY X;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Advanced Select/Binary Tree Nodes/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT N,
2 | CASE
3 | WHEN P IS NULL THEN 'Root'
4 | WHEN N IN (SELECT P FROM BST) THEN 'Inner'
5 | ELSE 'Leaf'
6 | END
7 | FROM BST
8 | ORDER BY N;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Advanced Select/New Companies/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT C.COMPANY_CODE,
2 | C.FOUNDER,
3 | (SELECT COUNT(DISTINCT LEAD_MANAGER_CODE)
4 | FROM LEAD_MANAGER L
5 | WHERE L.COMPANY_CODE = C.COMPANY_CODE),
6 | (SELECT COUNT(DISTINCT SENIOR_MANAGER_CODE)
7 | FROM SENIOR_MANAGER S
8 | WHERE S.COMPANY_CODE = C.COMPANY_CODE),
9 | (SELECT COUNT(DISTINCT MANAGER_CODE)
10 | FROM MANAGER M
11 | WHERE M.COMPANY_CODE = C.COMPANY_CODE),
12 | (SELECT COUNT(DISTINCT EMPLOYEE_CODE)
13 | FROM EMPLOYEE E
14 | WHERE E.COMPANY_CODE = C.COMPANY_CODE)
15 | FROM COMPANY C
16 | ORDER BY C.COMPANY_CODE ASC;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Advanced Select/The PADS/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT NAME || '(' || SUBSTR(OCCUPATION, 1, 1) || ')'
2 | FROM OCCUPATIONS
3 | ORDER BY NAME;
4 |
5 |
6 | SELECT 'There are a total of ' || X.O_COUNT || ' ' || LOWER(X.OCCUPATION) || 's.'
7 | FROM
8 | (SELECT OCCUPATION,
9 | COUNT(OCCUPATION) AS O_COUNT
10 | FROM OCCUPATIONS
11 | GROUP BY OCCUPATION) X
12 | ORDER BY X.O_COUNT,
13 | X.OCCUPATION;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Advanced Select/Type of Triangle/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT CASE
2 | WHEN A + B <= C
3 | OR A + C <= B
4 | OR B + C <= A THEN 'Not A Triangle'
5 | WHEN A = B
6 | AND B = C THEN 'Equilateral'
7 | WHEN A = B
8 | OR A = C
9 | OR B = C THEN 'Isosceles'
10 | ELSE 'Scalene'
11 | END
12 | FROM TRIANGLES;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Average Population/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT FLOOR(AVG(POPULATION))
2 | FROM CITY;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Japan Population/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT SUM(POPULATION)
2 | FROM CITY
3 | WHERE COUNTRYCODE = 'JPN';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Population Density Difference/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT MAX(POPULATION) - MIN(POPULATION)
2 | FROM CITY;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Revising Aggregations - Averages/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT AVG(POPULATION)
2 | FROM CITY
3 | WHERE DISTRICT = 'California';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Revising Aggregations - The Count Function/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT COUNT(*) FROM CITY WHERE POPULATION > 100000;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Revising Aggregations - The Sum Function/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT SUM(POPULATION)
2 | FROM CITY
3 | WHERE DISTRICT = 'California';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/The Blunder/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT CEIL(AVG(SALARY) - AVG(REPLACE(SALARY, '0', '')))
2 | FROM EMPLOYEES;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Top Earners/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT *
2 | FROM
3 | (SELECT MAX(MONTHS*SALARY),
4 | COUNT(EMPLOYEE_ID)
5 | FROM EMPLOYEE
6 | GROUP BY MONTHS*SALARY
7 | ORDER BY MONTHS*SALARY DESC)
8 | WHERE ROWNUM = 1;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 13/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(SUM(LAT_N), 4)
2 | FROM STATION
3 | WHERE LAT_N BETWEEN 38.7880 AND 137.2345;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 14/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(MAX(LAT_N), 4)
2 | FROM STATION
3 | WHERE LAT_N < 137.2345;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 15/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(LONG_W, 4)
2 | FROM STATION
3 | WHERE LAT_N =
4 | (SELECT MAX(LAT_N)
5 | FROM STATION
6 | WHERE LAT_N < 137.2345);
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 16/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(MIN(LAT_N), 4)
2 | FROM STATION
3 | WHERE LAT_N > 38.7780;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 17/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT *
2 | FROM
3 | ( SELECT ROUND(LONG_W, 4)
4 | FROM STATION
5 | WHERE LAT_N > 38.7780
6 | ORDER BY LAT_N ASC)
7 | WHERE ROWNUM = 1;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 18/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(MAX(LAT_N) - MIN(LAT_N) + MAX(LONG_W) - MIN(LONG_W), 4)
2 | FROM STATION;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 19/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(SQRT(POWER(MIN(LAT_N) - MAX(LAT_N), 2) + POWER(MIN(LONG_W) - MAX(LONG_W), 2)), 4)
2 | FROM STATION;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 2/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(SUM(LAT_N), 2),
2 | ROUND(SUM(LONG_W), 2)
3 | FROM STATION;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Aggregation/Weather Observation Station 20/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT ROUND(MEDIAN(LAT_N), 4)
2 | FROM STATION;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Alternative Queries/Draw The Triangle 1/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT RPAD('*', (21-LEVEL)*2, ' *')
2 | FROM DUAL CONNECT BY LEVEL <= 20;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Alternative Queries/Draw The Triangle 2/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT RPAD('*', 2 * LEVEL - 1, ' *')
2 | FROM DUAL CONNECT BY LEVEL <= 20;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Alternative Queries/Print Prime Numbers/Solution.sql:
--------------------------------------------------------------------------------
1 | WITH THOUSAND AS
2 | (SELECT *
3 | FROM
4 | (SELECT LEVEL LVL
5 | FROM DUAL CONNECT BY LEVEL <= 1000)
6 | WHERE LVL > 1)
7 | SELECT LISTAGG(T1.LVL, '&') WITHIN GROUP(ORDER BY T1.LVL)
8 | FROM THOUSAND T1
9 | WHERE T1.LVL <=
10 | (SELECT COUNT(DISTINCT T2.LVL) + 2
11 | FROM THOUSAND T2
12 | WHERE T2.LVL < T1.LVL
13 | AND MOD(T1.LVL, T2.LVL) > 0);
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Join/African Cities/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT CITY.NAME
2 | FROM CITY
3 | JOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODE
4 | WHERE CONTINENT = 'Africa';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Join/Asian Population/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT SUM(CITY.POPULATION)
2 | FROM CITY
3 | JOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODE
4 | WHERE COUNTRY.CONTINENT = 'Asia';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Join/Average Population of Each Continent/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT COUNTRY.CONTINENT, FLOOR(AVG(CITY.POPULATION))
2 | FROM CITY
3 | JOIN COUNTRY ON CITY.COUNTRYCODE = COUNTRY.CODE
4 | GROUP BY COUNTRY.CONTINENT;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Join/Contest Leaderboard/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT HACKER_ID,
2 | NAME,
3 | SUM(A)
4 | FROM
5 | (SELECT S.HACKER_ID,
6 | H.NAME,
7 | MAX(S.SCORE) A
8 | FROM SUBMISSIONS S
9 | INNER JOIN HACKERS H ON H.HACKER_ID=S.HACKER_ID
10 | WHERE S.SCORE!=0
11 | GROUP BY S.HACKER_ID,
12 | H.NAME,
13 | S.CHALLENGE_ID)
14 | GROUP BY HACKER_ID,
15 | NAME
16 | ORDER BY 3 DESC,
17 | 1;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Join/The Report/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT CASE
2 | WHEN G.GRADE < 8 THEN NULL
3 | ELSE S.NAME
4 | END AS NAME,
5 | G.GRADE,
6 | S.MARKS
7 | FROM STUDENTS S
8 | INNER JOIN GRADES G ON S.MARKS BETWEEN G.MIN_MARK AND G.MAX_MARK
9 | ORDER BY G.GRADE DESC,
10 | NAME,
11 | MARKS;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Join/Top Competitors/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT H.HACKER_ID,
2 | H.NAME
3 | FROM HACKERS H
4 | JOIN SUBMISSIONS S ON H.HACKER_ID = S.HACKER_ID
5 | JOIN DIFFICULTY D ON S.SCORE = D.SCORE
6 | JOIN CHALLENGES C ON S.CHALLENGE_ID = C.CHALLENGE_ID
7 | AND D.DIFFICULTY_LEVEL = C.DIFFICULTY_LEVEL
8 | GROUP BY H.HACKER_ID,
9 | H.NAME
10 | HAVING COUNT(S.SUBMISSION_ID) > 1
11 | ORDER BY COUNT(S.SUBMISSION_ID) DESC, HACKER_ID ASC;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Employee Names/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT NAME
2 | FROM EMPLOYEE
3 | ORDER BY NAME;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Employee Salaries/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT NAME
2 | FROM EMPLOYEE
3 | WHERE SALARY > 2000
4 | AND MONTHS < 10
5 | ORDER BY EMPLOYEE_ID;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Higher Than 75 Marks/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT NAME
2 | FROM STUDENTS
3 | WHERE MARKS > 75
4 | ORDER BY SUBSTR(NAME, -3), ID ASC;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Japanese Cities' Attributes/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT *
2 | FROM CITY
3 | WHERE COUNTRYCODE = 'JPN';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Japanese Cities' Names/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT NAME
2 | FROM CITY
3 | WHERE COUNTRYCODE = 'JPN';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Revising the Select Query I/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT *
2 | FROM CITY
3 | WHERE COUNTRYCODE = 'USA'
4 | AND POPULATION > 100000;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Revising the Select Query II/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT NAME
2 | FROM CITY
3 | WHERE COUNTRYCODE = 'USA'
4 | AND POPULATION > 120000;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Select All/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT *
2 | FROM CITY;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Select By ID/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT *
2 | FROM CITY
3 | WHERE ID = '1661';
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 1/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT CITY, STATE
2 | FROM STATION;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 10/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT CITY
2 | FROM STATION
3 | WHERE REGEXP_LIKE(CITY, '[^aeiou]$');
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 11/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT CITY
2 | FROM STATION
3 | WHERE REGEXP_LIKE(UPPER(CITY), '^[^AEIOU]')
4 | OR REGEXP_LIKE(UPPER(CITY), '[^AEIOU]$');
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 12/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT(CITY)
2 | FROM STATION
3 | WHERE REGEXP_LIKE(CITY, '^[^AEIOU].*[^AEIOU]$', 'i');
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 3/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT CITY
2 | FROM STATION
3 | WHERE MOD(ID, 2) = 0;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 4/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT COUNT(CITY) - COUNT(DISTINCT CITY)
2 | FROM STATION;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 5/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT *
2 | FROM
3 | (SELECT CITY, LENGTH(CITY)
4 | FROM STATION
5 | ORDER BY LENGTH(CITY), CITY)
6 | WHERE ROWNUM = 1
7 | UNION
8 | SELECT *
9 | FROM
10 | (SELECT CITY, LENGTH(CITY)
11 | FROM STATION
12 | ORDER BY LENGTH(CITY) DESC, CITY)
13 | WHERE ROWNUM = 1;
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 6/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT CITY
2 | FROM STATION
3 | WHERE UPPER(SUBSTR(CITY, 1, 1)) IN ('A','E','I','O','U');
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 7/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT CITY
2 | FROM STATION
3 | WHERE UPPER(SUBSTR(CITY, -1)) IN ('A','E','I','O','U');
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 8/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT(CITY)
2 | FROM STATION
3 | WHERE REGEXP_LIKE (UPPER(CITY), '^[AEIOU]')
4 | AND REGEXP_LIKE (UPPER(CITY), '[AEIOU]$');
--------------------------------------------------------------------------------
/HackerRank1/SQL/Basic Select/Weather Observation Station 9/Solution.sql:
--------------------------------------------------------------------------------
1 | SELECT DISTINCT CITY
2 | FROM STATION
3 | WHERE UPPER(SUBSTR(CITY, 1, 1)) NOT IN ('A','E','I','O','U');
--------------------------------------------------------------------------------
/HackerRank1/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | JavaInterviewQuestions
7 | com.javaquestions
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | HackerRank1
13 |
14 |
15 |
--------------------------------------------------------------------------------
/HackerRank2/contest/lambda_calculi9/StringReductions.scala:
--------------------------------------------------------------------------------
1 | object StringReductions extends App {
2 | println(Console.readLine.distinct)
3 | }
--------------------------------------------------------------------------------
/HackerRank2/contest/project_euler+/013_large_sum/LargeSum.java:
--------------------------------------------------------------------------------
1 | import java.math.BigInteger;
2 | import java.util.Scanner;
3 |
4 | public class LargeSum
5 | {
6 | public static void main(String[] args)
7 | {
8 | Scanner scanner = new Scanner(System.in);
9 | int numbers = Integer.parseInt(scanner.nextLine());
10 | BigInteger sum = BigInteger.ZERO;
11 | for (int i = 0; i < numbers; i++)
12 | {
13 | String input = scanner.nextLine();
14 | sum = sum.add(new BigInteger(input));
15 | }
16 | System.out.println(sum.toString().substring(0, 10));
17 | scanner.close();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/HackerRank2/contest/project_euler+/020_factorial_digit_sum/factorial_digit_sum.rb:
--------------------------------------------------------------------------------
1 | def factorial(n)
2 | fact = 1
3 | for i in 2..n do
4 | fact *= i
5 | end
6 | return fact
7 | end
8 |
9 |
10 | def sum_digits(number)
11 | chars = number.to_s.chars
12 | sum = 0
13 | chars.each { |char| sum += char.to_i }
14 | return sum
15 | end
16 |
17 | gets.chomp.to_i.times do
18 | n = gets.chomp.to_i
19 | puts sum_digits(factorial(n))
20 | end
21 |
--------------------------------------------------------------------------------
/HackerRank2/contest/week_of_code_22/CookieParty.scala:
--------------------------------------------------------------------------------
1 | object CookieParty {
2 |
3 | def main(args: Array[String]) {
4 | val sc = new java.util.Scanner (System.in)
5 | val n = sc.nextInt()
6 | val m = sc.nextInt()
7 |
8 | val lowestMultiplier = (m.toDouble / n).ceil.toLong
9 | val result = (lowestMultiplier * n - m).abs
10 | println(result)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/contest/week_of_code_23/GearsOfWar.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object GearsOfWar extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val queries = lines.tail.map(_.toInt)
6 |
7 | val rotate = queries.map(q => if(q % 2 == 0) "Yes" else "No")
8 | println(rotate.mkString("\n"))
9 | }
--------------------------------------------------------------------------------
/HackerRank2/contest/week_of_code_25/BetweenTwoSets.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object BetweenTwoSets extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val a = lines(1).split(" ").map(_.toInt)
6 | val b = lines(2).split(" ").map(_.toInt)
7 | val allNumbers = (a.max to b.min).toList
8 |
9 | val x = allNumbers.filter(num => a.forall(i => num % i == 0) && b.forall(j => j % num == 0))
10 | println(x.size)
11 | }
--------------------------------------------------------------------------------
/HackerRank2/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 | JavaInterviewQuestions
7 | com.javaquestions
8 | 1.0-SNAPSHOT
9 |
10 | 4.0.0
11 |
12 | HackerRank2
13 |
14 |
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/flipping_bits/FlippingBits.js:
--------------------------------------------------------------------------------
1 | function processData(input) {
2 | var numbers = input.split("\n").map(function(item) {return parseInt(item);});
3 | for(var i = 1; i < numbers.length; i++ ) {
4 | console.log((~numbers[i]) >>> 0);
5 | }
6 | }
7 |
8 | process.stdin.resume();
9 | process.stdin.setEncoding("ascii");
10 | _input = "";
11 | process.stdin.on("data", function (input) {
12 | _input += input;
13 | });
14 |
15 | process.stdin.on("end", function () {
16 | processData(_input);
17 | });
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/flipping_bits/FlippingBits.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object FlippingBits extends App {
4 | private[this] val MAX = java.lang.Long.parseLong("11111111111111111111111111111111", 2)
5 |
6 | val numbers = Source.stdin.getLines().drop(1).map(_.toLong)
7 | val flipped = numbers.map(_ ^ MAX)
8 | println(flipped.mkString("\n"))
9 | }
10 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/flipping_bits/flipping_bits.rb:
--------------------------------------------------------------------------------
1 | tests = gets.to_i
2 | tests.times do
3 | puts 0xffffffff ^ gets.to_i
4 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/lonely_integer/LonelyInteger.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object LonelyInteger extends App {
4 | val arr = (Source.stdin.getLines().toList)(1).split(" ").map(_.toInt)
5 | val groups = arr.groupBy(i => i)
6 | val uniqueElement = groups.keys.find(key => groups.get(key).get.size == 1)
7 | println(uniqueElement)
8 | }
9 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/lonely_integer/lonely_integer.rb:
--------------------------------------------------------------------------------
1 | length = gets.chomp.to_i
2 | array = gets.chomp.split.map { |e| e.to_i }
3 | hash = Hash.new
4 | array.each do |i|
5 | if hash[i].nil?
6 | hash[i] = 1
7 | else
8 | hash[i] += 1
9 | end
10 | end
11 |
12 | array.each { |a| puts a if hash[a] == 1}
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/maximizing_xor/MaximizingXor.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object MaximizingXor extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val l = lines(0).toInt
6 | val r = lines(1).toInt
7 | val maxXor = (l: Int, r: Int) => {
8 | var max = 0
9 | (l to r).foreach(
10 | i => {
11 | (l to r).foreach(
12 | j => {
13 | val xor = i ^ j
14 | if (xor > max) max = xor
15 | })
16 | }
17 | )
18 | max
19 | }
20 |
21 | println(maxXor(l, r))
22 | }
23 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/maximizing_xor/maximizing_xor.rb:
--------------------------------------------------------------------------------
1 | def maxXor(l, r)
2 | max = 0
3 | for i in l..r do
4 | for j in l..r do
5 | xor = i ^ j
6 | max = xor if xor > max
7 | end
8 | end
9 | return max
10 | end
11 |
12 |
13 | l = gets.to_i
14 | r = gets.to_i
15 | print maxXor(l, r)
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/sum_vs_xor/SumVsXor.scala:
--------------------------------------------------------------------------------
1 | object SumVsXor extends App {
2 | val n = Source.stdin.bufferedReader().readLine().toLong
3 | val satisfied = Math.pow(2L, if(n == 0L)
4 | 0
5 | else
6 | n.toBinaryString.count(_ == '0')).toLong
7 |
8 | println(satisfied)
9 | }
10 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/bit_manipulation/sum_vs_xor/sum_vs_xor.rb:
--------------------------------------------------------------------------------
1 | n = gets.strip.to_i
2 | binary = n.to_s(2)
3 | zeroes = binary.count("0")
4 | zeroes = 0 if n == 0
5 | result = 2**zeroes
6 |
7 | puts result
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/code_golf/fizzbuzz/Solution.scala:
--------------------------------------------------------------------------------
1 | object Solution extends App{for(i<-1 to 100)println(if(i%15==0)"FizzBuzz"else if(i%3==0)"Fizz"else if(i%5==0)"Buzz"else i)}
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/dynamic_programming/dynamic_programming.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/graph_theory/graph_theory.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/greedy/flowers/Flowers.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Flowers extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val definition = lines(0).split(" ").map(_.toInt)
6 | val n = definition(0)
7 | val k = definition(1)
8 | val prices = lines(1).split(" ").map(_.toInt)
9 | val descendingPrices = prices.sortWith((i, j) => i > j)
10 | val total = descendingPrices.indices.map(totalPrice).sum
11 | println(total)
12 |
13 | def totalPrice(index: Int): Int = {
14 | val factor = index / k
15 | (factor + 1) * descendingPrices(index)
16 | }
17 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/greedy/flowers/flowers.rb:
--------------------------------------------------------------------------------
1 | (n, k) = gets.chomp.split.map { |e| e.to_i }
2 | prices = gets.chomp.split.map { |e| e.to_i }
3 |
4 | prices.sort! { |i,j| j <=> i }
5 | result = 0
6 | n.times do |i|
7 | factor = i / k
8 | result += (factor + 1) * prices[i]
9 | end
10 | puts result
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/greedy/mark_and_toys/solution.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Solution extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val (n, k) = lines.head.split(" ").map(_.toInt).toList match {
6 | case a :: b :: Nil => (a, b)
7 | }
8 | val prices = lines.tail.head.split(" ").map(_.toInt).toList.sorted
9 |
10 | var sum = 0
11 | val toys = prices.takeWhile(p => {
12 | sum += p
13 | p <= sum
14 | })
15 |
16 | println(toys.length)
17 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/greedy/max_min/MaxMin.scala:
--------------------------------------------------------------------------------
1 |
2 | object MaxMin extends App {
3 | val size = readInt()
4 | val k = readInt()
5 | val input = (1 to size).map(_ => readInt()).toVector.sorted
6 | println((0 to (size - k)).map(i => input(i + (k-1)) - input(i)).min)
7 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/greedy/max_min/angry_children.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | k = gets.to_i
3 | candy = Array.new(n)
4 | for i in 0..n-1
5 | candy[i] = gets.to_i
6 | end
7 | candy.sort! {|l,j| l <=> j}
8 | unfairness = candy[candy.length - 1]
9 | for i in 0..candy.length - k do
10 | temp_unfairness = candy[i + k - 1] - candy[i]
11 | unfairness = temp_unfairness if unfairness > temp_unfairness
12 | end
13 | puts unfairness
14 |
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/greedy/two_arrays/two_arrays.rb:
--------------------------------------------------------------------------------
1 | def prove(arr1, arr2, sum)
2 | for i in 0..arr1.length - 1 do
3 | return "NO" if arr1[i] + arr2[i] < sum
4 | end
5 | return "YES"
6 | end
7 |
8 | test_cases = gets.chomp.to_i
9 | test_cases.times do
10 | (arr_length, sum) = gets.chomp.split.map { |e| e.to_i}
11 | arr1 = gets.chomp.split.map { |e| e.to_i}
12 | arr2 = gets.chomp.split.map { |e| e.to_i}
13 | arr1.sort! {|i, j| i <=> j}
14 | arr2.sort! { |i, j| j <=> i}
15 | puts prove(arr1, arr2, sum)
16 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/angry_professor/angry_professor.rb:
--------------------------------------------------------------------------------
1 | def before_class(arrivals)
2 | result = 0
3 | arrivals.each do |item|
4 | result += 1 if item <= 0
5 | end
6 | return result
7 | end
8 |
9 | tests = gets.to_i
10 | tests.times do |i|
11 | (students, cancelation) = gets.split(" ").map {|i| i.to_i}
12 | arrivals = gets.split(" ").map {|i| i.to_i}
13 | before = before_class(arrivals)
14 | if(cancelation > before)
15 | puts "YES"
16 | else
17 | puts "NO"
18 | end
19 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/apple_and_orange/apple_and_orange.rb:
--------------------------------------------------------------------------------
1 | s,t = gets.strip.split(' ')
2 | s = s.to_i
3 | t = t.to_i
4 | a,b = gets.strip.split(' ')
5 | a = a.to_i
6 | b = b.to_i
7 | m,n = gets.strip.split(' ')
8 | m = m.to_i
9 | n = n.to_i
10 | apple = gets.strip
11 | apple = apple.split(' ').map(&:to_i)
12 | orange = gets.strip
13 | orange = orange.split(' ').map(&:to_i)
14 |
15 | fallen_apples = apple.select {|ap| (a + ap >= s) && (a + ap <= t)}.count
16 | fallen_oranges = orange.select {|o| (b + o >= s) && (b + o <= t)}.count
17 |
18 | puts fallen_apples
19 | puts fallen_oranges
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/beautiful_days_at_the_movies/BeautifulDaysAtTheMovies.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object BeautifulDaysAtTheMovies extends App {
4 | val nums = Source.stdin.bufferedReader().readLine().split(" ").map(_.toInt)
5 | val start = nums(0)
6 | val end = nums(1)
7 | val d = nums(2)
8 |
9 | val beautifulNum = (start to end).count(num => {
10 | val reversed = num.toString.reverse.toInt
11 | val diff = (num - reversed).abs
12 | diff % d == 0
13 | })
14 |
15 | println(beautifulNum)
16 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/beautiful_days_at_the_movies/beautiful_days_at_the_movies.rb:
--------------------------------------------------------------------------------
1 | (s, e, d) = gets.strip.split.map(&:to_i)
2 |
3 | count = 0
4 | for i in s..e do
5 | reversed = i.to_s.reverse
6 | count += 1 if (i - reversed.to_i).abs % d == 0
7 | end
8 |
9 | puts count
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/beautiful_triplets/beautiful_triplets.rb:
--------------------------------------------------------------------------------
1 | (n, d) = gets.strip.split(" ").map {|i| i.to_i}
2 | array = gets.strip.split(" ").map {|i| i.to_i}
3 |
4 | triplets = 0
5 | for i in 0...(n-2)
6 | for j in (i+1)...(n-1)
7 | break if (array[j] - array[i] > d)
8 | for k in (j+1)...(n)
9 | break if (array[k] - array[j] > d)
10 | triplets += 1 if((array[k] - array[j] == d) && (array[j] - array[i] == d))
11 | end
12 | end
13 | end
14 |
15 | puts triplets
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/between_two_sets/BetweenTwoSets.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object BetweenTwoSets extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val a = lines(1).split(" ").map(_.toInt)
6 | val b = lines(2).split(" ").map(_.toInt)
7 | val allNumbers = (a.max to b.min).toList
8 |
9 | val x = allNumbers.filter(num => a.forall(i => num % i == 0) && b.forall(j => j % num == 0))
10 | println(x.size)
11 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/between_two_sets/between_two_sets.rb:
--------------------------------------------------------------------------------
1 | (n, m) = gets.split.map(&:to_i)
2 | a = gets.split.map(&:to_i)
3 | b = gets.split.map(&:to_i)
4 | a_max = a.max
5 | b_min = b.min
6 | all_numbers = (a_max..b_min).to_a
7 | result = all_numbers.select do |num|
8 | factor_of_a = a.all? { |i| num % i == 0 }
9 | factor_of_b = b.all? { |j| j % num == 0 }
10 | factor_of_a && factor_of_b
11 | end
12 |
13 | puts result.size
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/birthday_chocolate/solution.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Solution extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val bars = lines(1).split(" ").map(_.toInt).toList
6 | val dm = lines(2).split(" ").map(_.toInt).toList match {
7 | case i :: j :: Nil => (i, j)
8 | }
9 |
10 | val allConsecutives = bars.sliding(dm._2)
11 | val result = allConsecutives.count(bars => bars.sum == dm._1)
12 |
13 | println(result)
14 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/bon_appetit/BonAppetit.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object BonAppetit extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val k = lines.head.split(" ")(1).toInt
6 | val items = lines(1).split(" ").map(_.toInt)
7 | val actual = lines(2).toInt
8 | val charged = (items.sum - items(k)) / 2
9 |
10 | println(if(charged == actual) "Bon Appetit" else charged - actual)
11 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/bon_appetit/bon_appetit.rb:
--------------------------------------------------------------------------------
1 | (n, k) = gets.strip.split.map(&:to_i)
2 | items = gets.strip.split.map(&:to_i)
3 | actual = gets.strip.to_i
4 |
5 | sum = 0
6 | items.each{ |i| sum += i}
7 | charged = (sum - items[k]) / 2
8 |
9 | if(charged == actual)
10 | puts "Bon Appetit"
11 | else
12 | puts (actual - charged)
13 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/caesar_cipher/caesar_cipher.rb:
--------------------------------------------------------------------------------
1 | l = gets.to_i
2 | text = gets.to_s
3 | shift = gets.to_i
4 |
5 | text.each_codepoint do |c|
6 | if(c >= 'a'.ord && c <= 'z'.ord)
7 | print ((c - 'a'.ord + shift) % 26 + 'a'.ord).chr
8 | elsif (c >= 'A'.ord && c <= 'Z'.ord)
9 | print ((c - 'A'.ord + shift) % 26 + 'A'.ord).chr
10 | else
11 | print c.chr
12 | end
13 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/chocolate_feast/chocolate_feast.rb:
--------------------------------------------------------------------------------
1 | test_cases = t = gets.to_i
2 | test_cases.times {
3 | (n, c, m) = gets.split.map{|i| i.to_i}
4 |
5 | answer = 0
6 | chocolate = n / c
7 | answer += chocolate
8 |
9 | free_choco = chocolate / m
10 |
11 |
12 | while free_choco > 0 do
13 | answer += free_choco
14 | wrappers = free_choco * m
15 | chocolate -= wrappers
16 | chocolate += free_choco
17 | free_choco = chocolate / m
18 | end
19 |
20 | puts answer
21 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/counting_valleys/solution.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Solution extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val steps = lines.tail.head
6 |
7 | var valleys = 0
8 | var seaLevel = 0
9 | steps.foreach(c => {
10 | if(c == 'D') {
11 | seaLevel -= 1
12 | } else {
13 | seaLevel += 1
14 | }
15 | if(seaLevel == 0 && c == 'U') {
16 | valleys += 1
17 | }
18 | })
19 |
20 | println(valleys)
21 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/cut_the_sticks/CutTheSticks.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object CutTheSticks extends App {
4 | var sticks = Source.stdin.getLines().toList.tail.head.split(" ").map(_.toInt)
5 | while (!sticks.isEmpty) {
6 | println(sticks.length)
7 | val sortedSticks = sticks.sorted
8 | val min = sortedSticks(0)
9 | sticks = sortedSticks.filter(_ > min)
10 | }
11 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/cut_the_sticks/cut_the_sticks.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | sticks = gets.split.map(&:to_i)
3 | while(sticks.size > 0) do
4 | puts sticks.size
5 | sticks.sort!{|a, b| a <=> b}
6 | min = sticks[0]
7 | sticks = sticks.filter {|i| i > min}
8 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/day_of_the_programmer/solution.scala:
--------------------------------------------------------------------------------
1 | object solution extends App {
2 | val sc = new java.util.Scanner (System.in)
3 |
4 | val year = sc.nextInt
5 | val output = if (year == 1918)
6 | "26.09.1918"
7 | else if (((year <= 1917) && (year%4 == 0)) || ((year%400 == 0) || ((year%4 ==0) & (year%100 != 0))))
8 | "12.09." + year
9 | else
10 | "13.09." + year
11 |
12 | println(output)
13 | }
14 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/designer_pdf_viewer/DesignerPdfViewer.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object DesignerPdfViewer extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val heights = lines.head.split(" ").map(_.toInt)
6 | val word = lines(1)
7 | val characterIndexes = word.map(_ - 'a')
8 | val maxHeight = characterIndexes.map(heights(_)).max
9 |
10 | val square = word.length * maxHeight
11 | println(square)
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/designer_pdf_viewer/designer_pdf_viewer.rb:
--------------------------------------------------------------------------------
1 | heights = gets.strip.split.map(&:to_i)
2 | word = gets.strip
3 | charHeights = word.chars.map{|c| heights[c.ord - 97]}
4 | max = charHeights.max
5 | square = word.size * max
6 |
7 | puts square
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/divisible_sum_pairs/DivisibleSumPairs.scala:
--------------------------------------------------------------------------------
1 | object DivisibleSumPairs extends App {
2 | val lines = Source.stdin.getLines().toList
3 | val divisor = lines(0).split(" ").map(_.toInt).toList(1)
4 | val array = lines(1).split(" ").map(_.toInt)
5 |
6 | val indexPairs = array.indices.flatMap(i => array.indices.slice(i + 1, array.length).map(j => (i, j)))
7 | val divisible = indexPairs.count(pair => (array(pair._1) + array(pair._2)) % divisor == 0)
8 | println(divisible)
9 | }
10 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/divisible_sum_pairs/divisible_sum_pairs.rb:
--------------------------------------------------------------------------------
1 | (n, divisor) = gets.split(" ").map {|i| i.to_i}
2 | array = gets.split(" ").map {|i| i.to_i}
3 | count = 0
4 | for a in 0..(n-2) do
5 | for j in (a+1)..(n-1) do
6 | count += 1 if ((array[a] + array[j]) % divisor == 0)
7 | end
8 | end
9 |
10 | puts count
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/drawing_book/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int n = stdin.nextInt();
8 | int p = stdin.nextInt();
9 |
10 | int fromFront = p;
11 | int fromBack = n;
12 | if(n % 2 == 0) {
13 | fromBack = n + 1;
14 | }
15 | int result = Math.min(fromFront / 2, (fromBack - p) / 2);
16 | System.out.println(result);
17 |
18 | stdin.close();
19 | }
20 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/drawing_book/solution.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Solution extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val n = lines.head.toInt
6 | val p = lines.tail.head.toInt
7 |
8 | val fromFront = p
9 | val fromBack = if(n % 2 == 0) {
10 | n + 1
11 | } else {
12 | n
13 | }
14 | val result = List(fromFront / 2, (fromBack - p) / 2).min
15 |
16 | println(result)
17 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/encryption/Encryption.scala:
--------------------------------------------------------------------------------
1 | import scala.collection.immutable.TreeMap
2 |
3 | object Encryption extends App {
4 | val input = io.Source.stdin.bufferedReader().readLine()
5 | val height = Math.ceil(Math.sqrt(input.length))
6 | val width = Math.floor(Math.sqrt(input.length))
7 | val groupByColumn = TreeMap(input.indices.toList.groupBy(_ % height).toArray:_*).values
8 | val encrypted = groupByColumn.map(_.map(input.charAt).mkString("")).mkString(" ")
9 | println(encrypted)
10 | }
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/encryption/encryption.rb:
--------------------------------------------------------------------------------
1 | input = gets.chomp
2 | width = Math.sqrt(input.length).floor
3 | height = Math.sqrt(input.length).ceil
4 | result = ""
5 | for i in 0...height do
6 | j = i
7 | while j < input.length
8 | result += input[j]
9 | j += height
10 | end
11 | result += " "
12 | end
13 | puts result
14 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/equalize_the_array/EqualizeTheArray.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object EqualizeTheArray extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val array = lines(1).split(" ").map(_.toInt)
6 |
7 | val maxOccuredNumber = array.groupBy(n => n).map(_._2.length).max
8 | val toRemove = array.length - maxOccuredNumber
9 | println(toRemove)
10 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/equalize_the_array/equalize_the_array.rb:
--------------------------------------------------------------------------------
1 | n = gets.strip.to_i
2 | arr = gets.strip.split
3 |
4 | num_counts = Hash.new
5 | arr.each do |num|
6 | count = 0
7 | count = num_counts[num] if num_counts.has_key?(num)
8 | num_counts[num] = count + 1
9 | end
10 |
11 | max_count = 0
12 | num_counts.each_key do |key|
13 | count = num_counts[key]
14 | max_count = count if count > max_count
15 | end
16 |
17 | puts n - max_count
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/extra_long_factorials/ExtraLongFactorials.scala:
--------------------------------------------------------------------------------
1 | object ExtraLongFactorials extends App
2 | {
3 | def factorial(n: BigInt): BigInt =
4 | {
5 | if(n < 1) 1 else n * factorial(n - 1)
6 | }
7 |
8 | val n = io.Source.stdin.bufferedReader().readLine().toInt;
9 | println(factorial(n))
10 | }
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/extra_long_factorials/extra_long_factorials.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i;
2 |
3 | def factorial(n)
4 | if n <= 1
5 | return 1
6 | end
7 | return n * factorial(n - 1)
8 | end
9 |
10 | puts factorial(n)
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/find_digits/FindDigits.scala:
--------------------------------------------------------------------------------
1 | object FindDigits extends App {
2 | var inputs = io.Source.stdin.getLines().toList.tail
3 |
4 | inputs.foreach {
5 | in =>
6 | println(in.toCharArray.count(d =>
7 | d.getNumericValue != 0 && in.toInt % d.getNumericValue == 0))
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/find_digits/find_digits.rb:
--------------------------------------------------------------------------------
1 | t = gets.to_i
2 | t.times do
3 | num = gets.chomp.to_s
4 | result = 0
5 | num.split("").each do |c|
6 | c_num = c.to_i
7 | result +=1 if c_num > 0 && num.to_i % c_num == 0
8 | end
9 | puts result
10 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/flatland_space_stations/solution.rb:
--------------------------------------------------------------------------------
1 | (cities, stationCount) = gets.strip.split.map(&:to_i)
2 | stations = gets.strip.split.map(&:to_i).sort
3 |
4 | max = 0
5 | for i in (0...(stations.length - 1)) do
6 | cities_inside = stations[i + 1] - stations[i] - 1;
7 | d = (cities_inside / 2.0).ceil.to_i;
8 | max = d if(d > max)
9 | end
10 |
11 | max = stations[0] if(stations[0] - 0 > max)
12 | max = cities - 1 - stations[stationCount - 1] if(cities - 1 - stations[stationCount - 1] > max)
13 |
14 | puts max;
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/grading_students/GradingStudents.scala:
--------------------------------------------------------------------------------
1 | object GradingStudents extends App {
2 | val grades = Source.stdin.getLines().toList.tail.map(_.toInt)
3 | val finalGrades = grades.map(professorGradeRule)
4 |
5 | println(finalGrades.mkString("\n"))
6 |
7 | def professorGradeRule(grade: Int): Int = {
8 | val multiply5 = grade / 5
9 | val roundBy5 = if(grade % 5 == 0) multiply5 * 5 else (multiply5 + 1) * 5
10 | if(roundBy5 - grade < 3 && grade >= 38) roundBy5 else grade
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/grading_students/grading_students.rb:
--------------------------------------------------------------------------------
1 | def professor_grade_rule(grade)
2 | multiply5 = grade / 5
3 | roundBy5 = (grade % 5 == 0) ? (multiply5 * 5) : ((multiply5 + 1) * 5)
4 | return roundBy5 if(roundBy5 - grade < 3 && grade >= 38)
5 | return grade
6 | end
7 |
8 | n = gets.to_i
9 | n.times do
10 | grade = gets.to_i
11 | final_grade = professor_grade_rule(grade)
12 | puts final_grade
13 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/jumping_on_the_clouds/JumpingOnTheClouds.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object JumpingOnTheClouds extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val clouds = lines(1).split(" ").map(_.toInt)
6 |
7 | var steps = 0
8 | var index = 0
9 | while (index < clouds.length - 1) {
10 | if((index + 2 < clouds.length) && clouds(index + 2) != 1) {
11 | index = index + 2
12 | } else {
13 | index = index + 1
14 | }
15 | steps += 1
16 | }
17 |
18 | println(steps)
19 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/jumping_on_the_clouds/jumping_on_the_clouds.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | clouds = gets.split(" ").map{|i| i.to_i}
3 |
4 | steps = 0
5 | index = 0
6 | while (index < clouds.length - 1) do
7 | if((index + 2 < clouds.length) && clouds[index + 2] != 1)
8 | index = index + 2
9 | else
10 | index = index + 1
11 | end
12 | steps += 1
13 | end
14 |
15 | puts steps
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/jumping_on_the_clouds_revisited/JumpingOnTheCloudsRevisited.scala:
--------------------------------------------------------------------------------
1 | object JumpingOnTheCloudsRevisited extends App {
2 | val lines = Source.stdin.getLines().toList
3 | val nk = lines.head.split(" ").map(_.toInt)
4 | val n = nk(0)
5 | val k = nk(1)
6 | val clouds = lines(1).split(" ").map(_.toInt)
7 | var energy = 100
8 | var pos = k % n
9 | energy -= (if(clouds(pos) == 1) 3 else 1)
10 | while(pos != 0) {
11 | pos = (pos + k) % n
12 | energy -= (if(clouds(pos) == 1) 3 else 1)
13 | }
14 | println(energy)
15 | }
16 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/jumping_on_the_clouds_revisited/jumping_on_the_clouds_revisited.rb:
--------------------------------------------------------------------------------
1 | (n, k) = gets.split(" ").map(&:to_i)
2 | clouds = gets.split(" ").map(&:to_i)
3 |
4 | energy = 100
5 | pos = k % n
6 | energy -= ((clouds[pos] == 1) ? 3 : 1)
7 | while(pos != 0) do
8 | pos = (pos + k) % n
9 | energy -= ((clouds[pos] == 1) ? 3 : 1)
10 | end
11 | puts energy
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/kangaroo/kangaroo.rb:
--------------------------------------------------------------------------------
1 | def same_location(x1, v1, x2, v2)
2 | return "NO" if(v1 < v2)
3 | if(x1 < x2 && v1 > v2)
4 | xDiff = (x1 - x2).abs
5 | vDiff = (v1 - v2).abs
6 | if(xDiff % vDiff == 0)
7 | return "YES"
8 | else
9 | return "NO"
10 | end
11 | end
12 | "NO"
13 | end
14 |
15 | (x1, v1, x2, v2) = gets.strip.split(" ").map {|i| i.to_i}
16 | puts same_location(x1, v1, x2, v2)
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/lisas_workbook/lisas_workbook.rb:
--------------------------------------------------------------------------------
1 | (n, k) = gets.split.map {|i| i.to_i}
2 | problems_per_chapter = gets.split.map {|i| i.to_i}
3 | page = 1
4 | special_problems = 0
5 | n.times do |i|
6 | problems = problems_per_chapter[i]
7 | for p in 1..problems
8 | special_problems += 1 if p == page
9 | page += 1 if p != problems && p % k == 0
10 | end
11 | page += 1
12 | end
13 |
14 | puts special_problems
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/manasa_and_stones/manasa_stones.rb:
--------------------------------------------------------------------------------
1 | require "set"
2 |
3 | tests = gets.to_i
4 | tests.times do
5 | n = gets.to_i
6 | a = gets.to_i
7 | b = gets.to_i
8 | set = SortedSet.new([0])
9 | (n - 1).times do
10 | new_set = SortedSet.new
11 | set.each do |element|
12 | new_set << element + a
13 | new_set << element + b
14 | end
15 | set = new_set
16 | end
17 | puts set.to_a.join(" ")
18 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/mini-max_sum/MinMaxSum.scala:
--------------------------------------------------------------------------------
1 | object MinMaxSum {
2 |
3 | def main(args: Array[String]) {
4 | val ints = scala.io.Source.stdin.getLines.toList.head.split(" ").map(_.toLong)
5 | val minsum = ints.sorted.init.sum
6 | val maxsum = ints.sorted.tail.sum
7 | println(minsum + " " + maxsum)
8 | }
9 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/mini-max_sum/min_max_sum.rb:
--------------------------------------------------------------------------------
1 | nums = gets.strip.split(" ").map(&:to_i)
2 | nums.sort! {|a, b| a <=> b}
3 |
4 |
5 | min_sum = 0
6 | max_sum = 0
7 | for i in (0...(nums.length - 1)) do
8 | min_sum += nums[i]
9 | max_sum += nums[i + 1]
10 | end
11 |
12 |
13 | puts "" + min_sum.to_s + " " + max_sum.to_s
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/minimum_distances/MinimumDistances.scala:
--------------------------------------------------------------------------------
1 | object MinimumDistances extends App {
2 | val lines = Source.stdin.getLines().toList
3 | val array = lines(1).split(" ").map(_.toInt)
4 |
5 | val indexPairs = array.indices.flatMap(i => array.indices.slice(i + 1, array.length).map(j => (i, j)))
6 | val equalValues = indexPairs.filter(pair => array(pair._1) == array(pair._2))
7 | val distances = equalValues.map(pair => (pair._1 - pair._2).abs)
8 |
9 | val result = if(distances.isEmpty) -1 else distances.min
10 | println(result)
11 | }
12 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/minimum_distances/minimum_distances.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | arr = gets.split(" ").map {|i| i.to_i}
3 | min = 99999999
4 | for i in 0..(n-1)
5 | for j in (i+1)..n
6 | min = [min, (j - i).abs].min if (arr[j] == arr[i])
7 | end
8 | end
9 |
10 | min = -1 if(min == 99999999)
11 | puts min
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/repeated_string/RepeatedString.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object RepeatedString extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val string = lines.head
6 | val letters = lines(1).toLong
7 | val as = string.count(_ == 'a')
8 | val times = letters / string.length
9 | val rest = letters % string.length
10 |
11 | val totalAs = times * as + string.substring(0, rest.toInt).count(_ == 'a')
12 | println(totalAs)
13 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/repeated_string/repeated_string.rb:
--------------------------------------------------------------------------------
1 | s = gets.strip
2 | n = gets.strip.to_i
3 |
4 | as = s.count("a")
5 | times = n / s.size
6 | rest = n % s.size
7 |
8 | totalAs = times * as + s.slice(0, rest).count("a")
9 | puts totalAs
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/save_the_prisoner/save_the_prisoner.rb:
--------------------------------------------------------------------------------
1 | def saved_prisoner(line)
2 | numbers = line.split(" ").map {|i| i.to_i}
3 | prisoners = numbers[0]
4 | sweets = numbers[1]
5 | startId = numbers[2]
6 |
7 | saved = (((sweets % prisoners) + startId) % prisoners) - 1;
8 | return prisoners if (saved == 0)
9 | saved
10 | end
11 |
12 | n = gets.to_i
13 | n.times do
14 | puts saved_prisoner(gets)
15 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/sequence_equation/SequenceEquation.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Solution extends App {
4 | val inputLines = Source.stdin.getLines().toList
5 | val n = inputLines.head.toInt
6 | val elements = inputLines.tail.head.split(" ").map(_.toInt)
7 |
8 | val y = (1 to n).map(i => {
9 | val index = elements.indexOf(i)
10 | val value1 = index + 1
11 | val index2 = elements.indexOf(value1)
12 | index2
13 | })
14 |
15 | println(y.mkString("\n"))
16 | }
17 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/sequence_equation/Solution.scala:
--------------------------------------------------------------------------------
1 | object Solution extends App {
2 | val inputLines = Source.stdin.getLines().toList
3 | val n = inputLines.head.toInt
4 | val elements = inputLines.tail.head.split(" ").map(_.toInt)
5 |
6 | val y = (1 to n).map(i => {
7 | val index = elements.indexOf(i)
8 | val value1 = index + 1
9 | val index2 = elements.indexOf(value1)
10 | index2
11 | })
12 |
13 | println(y.mkString("\n"))
14 | }
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/service_lane/ServiceLane.scala:
--------------------------------------------------------------------------------
1 | object ServiceLane extends App {
2 | val lines = io.Source.stdin.getLines().toList
3 | val lanes = lines(1).split(" ").map(_.toInt)
4 | val segments = lines.drop(2)
5 | val vehicles = segments.map(width(lanes, _))
6 | println(vehicles.mkString("\n"))
7 |
8 | def width(lanes: Array[Int], inputLane: String): Int = {
9 | val arr = inputLane.split(" ").map(_.toInt)
10 | lanes.slice(arr(0), arr(1) + 1).min
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/service_lane/service_lane.rb:
--------------------------------------------------------------------------------
1 | (length, tests) = gets.split(" ").map{ |i| i.to_i }
2 | lanes = gets.split(" ").map{ |i| i.to_i }
3 |
4 | tests.times do
5 | arr = gets.split(" ").map{ |i| i.to_i }
6 | puts lanes.slice(arr[0], arr[1] - arr[0] + 1).min
7 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/sherlock_and_squares/sherlock_and_squares.rb:
--------------------------------------------------------------------------------
1 | tests = gets.to_i
2 | tests.times do
3 | (lower, upper) = gets.split(" ").map {|i| i.to_i}
4 | square_numbers = 0
5 | if(lower == upper)
6 | if (Math.sqrt(lower) == (Math.sqrt(lower)).ceil)
7 | puts 1
8 | else
9 | puts 0
10 | end
11 | else
12 | puts ((Math.sqrt(upper)).floor - (Math.sqrt(lower)).ceil + 1).to_i
13 | end
14 | end
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/sock_merchant/SockMerchant.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object SockMerchant extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val socks = lines(1).split(" ").map(_.toInt)
6 | val sockGroups = socks.groupBy(c => c)
7 | val sockGroupPairs = sockGroups.map(group => group._2.length / 2)
8 | val pairs = sockGroupPairs.sum
9 |
10 | println(pairs)
11 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/sock_merchant/sock_merchant.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | socks = gets.split(" ")
3 | sock_groups = Hash.new
4 | socks.each do |s|
5 | if !sock_groups.include?(s)
6 | sock_groups[s] = 1
7 | else
8 | count = sock_groups[s]
9 | sock_groups[s] = count + 1
10 | end
11 | end
12 |
13 | pairs = 0
14 | sock_groups.values.each { |v| pairs += v / 2}
15 |
16 | puts pairs
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/strange_counter/StrangeCounter.scala:
--------------------------------------------------------------------------------
1 | object StrangeCounter extends App {
2 | val sc = new java.util.Scanner (System.in)
3 | val t = sc.nextLong()
4 |
5 | val cycle = Math.sqrt((t.toDouble / 3).ceil).ceil.toLong
6 | val cycleEndTime = cycleEnd(t, 0, 3)
7 | val timeDiff = cycleEndTime - t
8 | val finalValue = timeDiff + 1
9 |
10 | println(finalValue)
11 |
12 | def cycleEnd(time: Long, start: Long, step: Long): Long = {
13 | if(start > time) {
14 | return start
15 | }
16 | cycleEnd(time, start + step, step * 2)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/strange_counter/strange_counter.rb:
--------------------------------------------------------------------------------
1 | def cycle_end(time, start, step)
2 | return start if(start > time)
3 | cycle_end(time, start + step, step * 2)
4 | end
5 |
6 | t = gets.to_i
7 | cycle_end_time = cycle_end(t, 0, 3)
8 | time_diff = cycle_end_time - t
9 | final_value = time_diff + 1
10 | puts final_value
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/the_hurdle_race/TheHurdleRace.scala:
--------------------------------------------------------------------------------
1 | object TheHurdleRace extends App {
2 | val sc = new java.util.Scanner (System.in)
3 | val n = sc.nextInt()
4 | val k = sc.nextInt()
5 | var height = new Array[Int](n)
6 | for(height_i <- 0 until n) {
7 | height(height_i) = sc.nextInt()
8 | }
9 |
10 | val maxHeight = height.max
11 | val beverages = if(maxHeight > k) maxHeight - k else 0
12 |
13 | println(beverages)
14 | }
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/the_hurdle_race/the_hurdle_race.rb:
--------------------------------------------------------------------------------
1 | (n, k) = gets.split.map(&:to_i)
2 | heights = gets.split.map(&:to_i)
3 | max_height = heights.max
4 |
5 | beverages = 0
6 | beverages = (max_height - k) if max_height > k
7 |
8 | puts beverages
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/utopian_tree/UtopianTree.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object UtopianTree extends App {
4 | val nums = Source.stdin.getLines().toList.tail.map(_.toInt)
5 | nums.foreach(i => println(tree(0, i, 1)))
6 |
7 | def tree(actualCycle: Int, cycles: Int, height: Int): Int = {
8 | if(actualCycle == cycles) {
9 | return height
10 | }
11 | if(actualCycle % 2 == 0) tree(actualCycle + 1, cycles, height * 2)
12 | else tree(actualCycle + 1, cycles, height + 1)
13 | }
14 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/utopian_tree/utopian_tree.rb:
--------------------------------------------------------------------------------
1 | def tree(actualCycle, cycles, height)
2 | return height if(actualCycle == cycles)
3 | return tree(actualCycle + 1, cycles, height * 2) if(actualCycle % 2 == 0)
4 | tree(actualCycle + 1, cycles, height + 1)
5 | end
6 |
7 | tests = gets.to_i
8 | tests.times do
9 | cycles = gets.to_i
10 | puts tree(0, cycles, 1)
11 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/viral_advertising/ViralAdvertising.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object ViralAdvertising extends App {
4 | val n = Source.stdin.bufferedReader().readLine().toInt
5 |
6 | println(like(5).take(n).sum)
7 |
8 |
9 | def like(start: Long): Stream[Long] = {
10 | val liked = start / 2
11 | val received = liked * 3
12 | liked #:: like(received)
13 | }
14 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/implementation/viral_advertising/viral_advertising.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 |
3 | total_liked = 0
4 | day_start_people = 5
5 | for i in 0...n do
6 | day_liked = day_start_people / 2
7 | received = day_liked * 3
8 | total_liked = total_liked + day_liked
9 | day_start_people = received
10 | end
11 |
12 | puts total_liked
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/search/ice_cream_parlor/ice_cream_parlor.rb:
--------------------------------------------------------------------------------
1 | tests = gets.chomp.to_i
2 | tests.times do
3 | m = gets.chomp.to_i
4 | n = gets.chomp.to_i
5 | flavors = gets.chomp.split.map { |e| e.to_i }
6 | for i in 0...flavors.length - 1 do
7 | for j in i + 1...flavors.length do
8 | puts "#{i + 1} #{j + 1}" if flavors[i] + flavors[j] == m
9 | end
10 | end
11 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/search/missing_numbers/missing_numbers.rb:
--------------------------------------------------------------------------------
1 | a_length = gets.chomp.to_i
2 | a = gets.chomp.split.map { |e| e.to_i }
3 | b_length = gets.chomp.to_i
4 | b = gets.chomp.split.map { |e| e.to_i }
5 | a_hash = Hash.new(0)
6 | b_hash = Hash.new(0)
7 | a.each { |e| a_hash[e] += 1}
8 | b.each { |e| b_hash[e] += 1}
9 |
10 | result = []
11 | b_hash.each_key do |key|
12 | b_value = b_hash[key]
13 | a_value = a_hash[key]
14 | result << key if a_value.nil? || b_value > a_value
15 | end
16 |
17 | result.sort! { |i, j| i <=> j }
18 | puts result.join(" ")
19 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/search/pairs/pairs.rb:
--------------------------------------------------------------------------------
1 | (length, diff) = gets.split.map{|s| s.to_i}
2 | arr = gets.split.map{|s| s.to_i}.sort{|a,b| a <=> b}
3 | pairs = 0
4 | for i in 0...arr.size - 1
5 | for j in (i+1)...arr.size
6 | if(arr[j] - arr[i] == diff)
7 | pairs += 1
8 | break
9 | end
10 | end
11 | end
12 | puts pairs
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/sorting/closest_numbers/ClosestNumbers.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object ClosestNumbers extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val array = lines(1).split(" ").map(_.toInt)
6 | val sortedArray = array.sorted
7 | val pairs = sortedArray.sliding(2).toList
8 | val minDifference = pairs.map(arr => arr(1) - arr(0)).min
9 | val elements = pairs.filter(arr => arr(1) - arr(0) == minDifference).flatten.sorted
10 | println(elements.mkString(" "))
11 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/sorting/closest_numbers/closest_numbers.rb:
--------------------------------------------------------------------------------
1 | tests = gets.to_i
2 | tests.times do
3 | arr = gets.to_s.split.map{|s| s.to_i}.sort{|a, b| a <=> b}
4 | min_diff = 100000000;
5 | for i in 0...(arr.size - 1)
6 | diff = arr[i + 1] - arr[i]
7 | min_diff = diff if(diff < min_diff)
8 | end
9 | elements = []
10 | for i in 0...(arr.size - 1)
11 | diff = arr[i + 1] - arr[i]
12 | if(diff == min_diff)
13 | elements << arr[i]
14 | elements << arr[i + 1]
15 | end
16 | end
17 | elements.sort!{|a, b| a <=> b}
18 | puts elements.join(" ")
19 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/sorting/counting_sort_1/solution.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Solution{
4 | def countingSort(arr: Array[Int]): Array[Int] = {
5 | val countsOfNumbers = arr.sorted.groupBy(i => i).map(a => (a._1, a._2.length))
6 |
7 | (0 until 100).map(countsOfNumbers.getOrElse(_, 0)).toArray
8 | }
9 |
10 | def main(args: Array[String]) {
11 | val lines = Source.stdin.getLines().toList
12 | val arr = lines.tail.head.split(" ").map(_.toInt)
13 | val result = countingSort(arr)
14 | println (result.mkString(" "))
15 | }
16 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/sorting/intro_to_tutorial_challenges/IntroToTutorialChallenges.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object IntroToTutorialChallenges extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val searchedValue = lines(0).toInt
6 | val array = lines(2).split(" ").map(_.toInt)
7 |
8 | val valPosition = getPosition(array, searchedValue)
9 | println(valPosition)
10 |
11 | def getPosition(array: Array[Int], value: Int): Int = {
12 | array.indexOf(value)
13 | }
14 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/sorting/intro_to_tutorial_challenges/intro_to_tutorial_challenges.rb:
--------------------------------------------------------------------------------
1 | def get_position(arr, val)
2 | (arr.size - 1).times do |i|
3 | return i if(val == arr[i])
4 | end
5 | end
6 |
7 | searched_value = gets.to_s.chomp.to_i
8 | array_length = gets.to_s.chomp.to_i
9 | arr = gets.to_s.split.map{ |i| i.to_i }
10 |
11 | position = get_position(arr, searched_value)
12 | puts position
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/alternating_characters/AlternatingCharacters.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object AlternatingCharacters extends App {
4 | val strings = Source.stdin.getLines().drop(1)
5 |
6 | println(strings.map(deletions).mkString("\n"))
7 |
8 | def deletions(s: String):Int = {
9 | var last = s.charAt(0)
10 | var dels = 0
11 | s.drop(1).foreach {
12 | c => {
13 | if (last == c) {
14 | dels += 1
15 | } else {
16 | last = c
17 | }
18 | }
19 | }
20 | dels
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/alternating_characters/alternating_characters.rb:
--------------------------------------------------------------------------------
1 | def deletions(s)
2 | last = s[0]
3 | dels = 0
4 | for i in 1..(s.length) do
5 | if last == s[i]
6 | dels += 1
7 | else
8 | last = s[i]
9 | end
10 | end
11 | dels
12 | end
13 |
14 | var tests = gets.to_i
15 | tests.times do
16 | s = gets
17 | puts deletions(s)
18 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/anagram/Anagram.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Anagram extends App {
4 | val strings = Source.stdin.getLines().drop(1)
5 |
6 | val charsToDelete = strings.map(numOfChanges)
7 | println(charsToDelete.mkString("\n"))
8 |
9 | def numOfChanges(s: String): Int = {
10 | if (s.length % 2 != 0)
11 | -1
12 | else {
13 | val half1 = s.substring(0, s.length / 2)
14 | val half2 = s.substring(s.length / 2)
15 | half1.length - half1.intersect(half2).length
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/anagram/anagram.rb:
--------------------------------------------------------------------------------
1 | def substitutions(input)
2 | half1 = input.slice(0, input.length / 2)
3 | half2 = input.slice(input.length / 2, input.length)
4 |
5 | for i in 0..half1.length - 1 do
6 | half2.sub!(half1[i], "") if half2.include?(half1[i])
7 | end
8 | return half2.length
9 | end
10 |
11 | tests = gets.chomp.to_i
12 | tests.times do
13 | input = gets.chomp
14 | result = 0
15 | if input.length % 2 != 0
16 | result = -1
17 | else
18 | result = substitutions(input)
19 | end
20 |
21 | puts result
22 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/beautiful_binary_string/BeautifulBinaryString.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class BeautifulBinaryString {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int l = Integer.parseInt(stdin.nextLine());
8 | String s = stdin.nextLine();
9 | String beautiful = s.replaceAll("010", "b");
10 | int changes = beautiful.replaceAll("[01]", "").length();
11 | System.out.println(changes);
12 | stdin.close();
13 | }
14 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/beautiful_binary_string/BeautifulBinaryString.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const processData = input => {
4 | const lines = input.split('\n');
5 | const s = lines[1];
6 | const beautiful = s.replace(/010/g, "b");
7 | const changes = beautiful.replace(/[01]/g, "").length;
8 | console.log(changes);
9 | };
10 |
11 | process.stdin.resume();
12 | process.stdin.setEncoding("ascii");
13 |
14 | let _input = "";
15 | process.stdin.on("data", input => _input += input);
16 | process.stdin.on("end", () => processData(_input));
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/beautiful_binary_string/BeautifulBinaryString.scala:
--------------------------------------------------------------------------------
1 | object BeautifulBinaryString {
2 |
3 | def main(args: Array[String]) {
4 | val sc = new java.util.Scanner (System.in)
5 | val n = sc.nextInt()
6 | val B = sc.next()
7 |
8 | val beautiful = B.replaceAll("010", "b")
9 | val changes = beautiful.count(_ == 'b')
10 | println(changes)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/beautiful_binary_string/beautiful_binary_string.rb:
--------------------------------------------------------------------------------
1 | l = gets.to_i
2 | s = gets.to_s.strip
3 |
4 | s.gsub!(/010/, "b")
5 | s.gsub!(/[01]/, "")
6 | puts s.length()
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/camelcase/CamelCase.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class CamelCase {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | String text = stdin.nextLine();
8 | String[] words = text.split("[A-Z]");
9 | System.out.println(words.length);
10 | stdin.close();
11 | }
12 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/camelcase/CamelCase.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const processData = input => {
4 | const line = input;
5 | const words = line.split(/[A-Z]/g);
6 | console.log(words.length);
7 | };
8 |
9 | process.stdin.resume();
10 | process.stdin.setEncoding("ascii");
11 |
12 | let _input = "";
13 | process.stdin.on("data", input => _input += input);
14 | process.stdin.on("end", () => processData(_input));
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/camelcase/CamelCase.scala:
--------------------------------------------------------------------------------
1 | object CamelCase {
2 |
3 | def main(args: Array[String]) {
4 | val sc = new java.util.Scanner (System.in)
5 | val s = sc.next()
6 | println(s.split("[A-Z]").length)
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/camelcase/camelcase.rb:
--------------------------------------------------------------------------------
1 | text = gets.strip
2 | words = text.split(/[A-Z]/)
3 | puts words.size
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/funny_string/FunnyString.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object FunnyString extends App {
4 | val lines = Source.stdin.getLines().drop(1)
5 | val funnies = lines.map(funny).map(toText)
6 | println(funnies.mkString("\n"))
7 |
8 | def funny(s: String): Boolean = {
9 | val l = s.length
10 | s.indices.take(l - 1).forall(i =>
11 | (s.charAt(i) - s.charAt(i + 1)).abs == (s.charAt(l - i - 2) - s.charAt(l - i - 1)).abs)
12 | }
13 |
14 | def toText(b: Boolean): String = {
15 | if(b) "Funny" else "Not Funny"
16 | }
17 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/funny_string/funny_string.rb:
--------------------------------------------------------------------------------
1 | def funny?(s)
2 | for i in 0...s.length() - 1
3 | return false if((s[i].ord - s[i + 1].ord).abs != (s[s.length() - i - 2].ord - s[s.length() - i - 1].ord).abs)
4 | end
5 | return true
6 | end
7 |
8 | tests = gets.to_i
9 | tests.times do
10 | s = gets.to_s.strip
11 | if funny?(s)
12 | puts "Funny"
13 | else
14 | puts "Not Funny"
15 | end
16 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/gemstones/Gemstones.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Gemstones extends App {
4 | val strings = Source.stdin.getLines().drop(1).toList
5 |
6 | val first = strings(0)
7 | val gemstones = strings.drop(1).foldLeft(first)(_ intersect _)
8 | println(gemstones.size)
9 | }
10 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/gemstones/gemstones.rb:
--------------------------------------------------------------------------------
1 | string_count = gets.to_i
2 | first = gets.chars.uniq
3 | (string_count - 1).times do
4 | s = gets.chars.uniq
5 | first = first & s
6 | end
7 | puts first.length
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/making_anagrams/solution.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Solution extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val string1 = lines.head
6 | val string2 = lines.tail.head
7 |
8 | val commonChars = string1.intersect(string2)
9 |
10 | val toRemove = (string1.length - commonChars.length) + (string2.length - commonChars.length)
11 |
12 | println(toRemove)
13 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/mars_exploration/MarsExploration.scala:
--------------------------------------------------------------------------------
1 | object MarsExploration extends App {
2 | val line = Source.stdin.getLines().toList.head
3 | val tris = line.grouped(3)
4 | val sosDiffs = tris.map(diffSignal)
5 | println(sosDiffs.sum)
6 |
7 | def diffSignal(s: String): Long = {
8 | (if(s(0) == 'S') 0 else 1) +
9 | (if(s(1) == 'O') 0 else 1) +
10 | (if(s(2) == 'S') 0 else 1)
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/mars_exploration/mars_exploration.rb:
--------------------------------------------------------------------------------
1 | msg = gets.to_s.strip
2 | index = 0
3 | result = 0
4 | while index < msg.length do
5 | result += 1 if msg[index] != 'S'
6 | result += 1 if msg[index + 1] != 'O'
7 | result += 1 if msg[index + 2] != 'S'
8 | index += 3
9 | end
10 |
11 | puts result
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/pangrams/Pangrams.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Pangrams extends App {
4 | println(
5 | if(Source.stdin.bufferedReader().readLine().toLowerCase().distinct.replaceAll("\\s+", "").distinct.length == 26)
6 | "pangram"
7 | else
8 | "not pangram"
9 | )
10 | }
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/pangrams/pangrams.rb:
--------------------------------------------------------------------------------
1 | require 'set'
2 |
3 | s = Set.new(gets.downcase.gsub(/\s+/, "").chars())
4 | if(s.size() == 26)
5 | puts "pangram"
6 | else
7 | puts "not pangram"
8 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/string_construction/StringConstruction.scala:
--------------------------------------------------------------------------------
1 | object StringConstruction extends App {
2 | val lines = Source.stdin.getLines()
3 | val strings = lines.toList.tail
4 | val costs = strings.map(_.distinct.length)
5 | println(costs.mkString("\n"))
6 | }
7 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/string_construction/string_construction.rb:
--------------------------------------------------------------------------------
1 | def cost(s)
2 | map = Hash.new
3 | for i in 0...(s.size)
4 | map[s[i]] = true
5 | end
6 | map.size
7 | end
8 |
9 | n = gets.to_i
10 | n.times do
11 | s = gets.to_s.strip
12 | puts cost(s)
13 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/super_reduced_string/SuperReducedString.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object SuperReducedString extends App {
4 | val line = Source.stdin.getLines().toList.head
5 | val reduced = line.foldLeft("")(stringReduce)
6 | println(if(reduced.isEmpty) "Empty String" else reduced)
7 |
8 | def stringReduce(acc: String, c: Char): String = {
9 | if(acc.length > 0 && acc.charAt(acc.length - 1) == c) acc.substring(0, acc.length - 1) else acc + c
10 | }
11 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/super_reduced_string/super_reduced_string.rb:
--------------------------------------------------------------------------------
1 | s = gets.strip
2 | acc = ""
3 | for i in 0...(s.length) do
4 | c = s[i]
5 | if(acc.length > 0 && acc[acc.length - 1] == c)
6 | acc = acc.slice(0, acc.length - 1)
7 | else
8 | acc = acc + c
9 | end
10 | end
11 |
12 | if(acc.length == 0)
13 | puts "Empty String"
14 | else
15 | puts acc
16 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/the_love-letter_mystery/TheLoveLetterMystery.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object TheLoveLetterMystery extends App {
4 | val lines = Source.stdin.getLines().drop(1)
5 | val diffs = lines.map(changes)
6 | println(diffs.mkString("\n"))
7 |
8 | def changes(s: String): Int = {
9 | val halves = s.splitAt(s.length / 2)
10 | val reverted2 = halves._2.reverse
11 | halves._1.indices.map(i => ordinalDiff(halves._1.charAt(i), reverted2.charAt(i))).sum
12 | }
13 |
14 | def ordinalDiff(ch1: Char, ch2: Char): Int = {
15 | (ch2 - ch1).abs
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/strings/the_love-letter_mystery/loveletter_mystery.rb:
--------------------------------------------------------------------------------
1 | tests = gets.chomp.to_i
2 | tests.times do
3 | input = gets.chomp
4 | changes = 0
5 | for i in 0...input.length / 2
6 | char_front = input[i]
7 | char_back = input[input.length - 1 - i]
8 | diff = (char_front.ord - char_back.ord).abs
9 | changes += diff
10 | end
11 | puts changes
12 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/a_very_big_sum/AVeryBigSum.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class AVeryBigSum {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int numbers = Integer.parseInt(stdin.nextLine());
8 | String[] integers = stdin.nextLine().split(" ");
9 | long sum = 0;
10 | for(int i = 0; i < numbers; i++)
11 | {
12 | sum += Long.parseLong(integers[i]);
13 | }
14 | System.out.println(sum);
15 | stdin.close();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/a_very_big_sum/AVeryBigSum.js:
--------------------------------------------------------------------------------
1 | var sum = 0;
2 | function processData(input) {
3 | var lines = input.split("\n");
4 | var n = parseInt(lines[0]);
5 | var arr = lines[1].split(" ");
6 | for (var i = 0; i < n; i++) {
7 | sum += parseInt(arr[i]);
8 | }
9 | console.log(sum);
10 | }
11 |
12 | process.stdin.resume();
13 | process.stdin.setEncoding("ascii");
14 | _input = "";
15 | process.stdin.on("data", function (input) {
16 | _input += input;
17 | });
18 |
19 | process.stdin.on("end", function () {
20 | processData(_input);
21 | });
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/a_very_big_sum/AVeryBigSum.scala:
--------------------------------------------------------------------------------
1 | object AVeryBigSum extends App
2 | {
3 | val console = io.Source.stdin.bufferedReader()
4 | val n = console.readLine().toInt;
5 | println(console.readLine().split(" ").map(_.toInt).sum)
6 | }
7 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/a_very_big_sum/a_very_big_sum.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | arr = gets.split(" ").map { |c| c.to_i }
3 | sum = 0
4 | for i in arr do
5 | sum += i
6 | end
7 | puts sum
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/circular_array_rotation/circular_array_rotation.rb:
--------------------------------------------------------------------------------
1 | (n, k, q) = gets.split(" ").map(&:to_i)
2 | elements = gets.split(" ").map(&:to_i)
3 | queries = []
4 | q.times do
5 | queries << gets.to_i
6 | end
7 |
8 | rotationPos = k % n
9 | part1 = elements.slice(0, n - rotationPos)
10 | part2 = elements.slice(n - rotationPos, n)
11 | final_array = part2.concat(part1)
12 |
13 | q.times do |i|
14 | puts final_array[queries[i]]
15 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/compare_the_triplets/CompareTheTriplets.scala:
--------------------------------------------------------------------------------
1 | object CompareTheTriplets extends App {
2 | val lines = Source.stdin.getLines().toList
3 | val alicesRating = lines(0).split(" ").map(_.toInt)
4 | val bobsRating = lines(1).split(" ").map(_.toInt)
5 |
6 | val differentRatings = alicesRating.zip(bobsRating).filter(pair => pair._1 != pair._2)
7 | val aliceScore = differentRatings.count(pair => pair._1 > pair._2)
8 | val bobScore = differentRatings.length - aliceScore
9 |
10 | println(aliceScore + " " + bobScore)
11 | }
12 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/compare_the_triplets/compare_the_triplets.rb:
--------------------------------------------------------------------------------
1 | a0, a1, a2 = gets.strip.split(' ')
2 | a0 = a0.to_i
3 | a1 = a1.to_i
4 | a2 = a2.to_i
5 | b0, b1, b2 = gets.strip.split(' ')
6 | b0 = b0.to_i
7 | b1 = b1.to_i
8 | b2 = b2.to_i
9 |
10 | alice_score = 0
11 | bob_score = 0
12 |
13 | alice_score = alice_score + 1 if a0 > b0
14 | alice_score = alice_score + 1 if a1 > b1
15 | alice_score = alice_score + 1 if a2 > b2
16 |
17 | bob_score = bob_score + 1 if a0 < b0
18 | bob_score = bob_score + 1 if a1 < b1
19 | bob_score = bob_score + 1 if a2 < b2
20 |
21 | puts "#{alice_score} #{bob_score}"
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/diagonal_difference/DiagonalDifference.scala:
--------------------------------------------------------------------------------
1 | object DiagonalDifference extends App {
2 | val lines = io.Source.stdin.getLines().toList
3 | val n = lines.head.toInt
4 | val matrix = lines.tail.toArray.map(_.split(" ").map(_.toInt))
5 |
6 | var leftRight = 0
7 | var rightLeft = 0
8 | (0 until n).foreach {
9 | i =>
10 | leftRight += (matrix(i))(i)
11 | rightLeft += (matrix(i)(n - i - 1))
12 | }
13 | println((leftRight - rightLeft).abs)
14 | }
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/diagonal_difference/diagonal_difference.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | leftRight = 0
3 | rightLeft = 0
4 | n.times do |i|
5 | row = gets.to_s.split(" ").map { |s| s.to_i}
6 | leftRight += row[i]
7 | rightLeft += row[n - i - 1]
8 | end
9 |
10 | puts (leftRight - rightLeft).abs
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/plus_minus/PlusMinus.scala:
--------------------------------------------------------------------------------
1 | import java.util.Locale
2 |
3 | object PlusMinus extends App {
4 | val console = io.Source.stdin.bufferedReader()
5 |
6 | val n = console.readLine().toInt
7 | val arr = console.readLine().split(" ").map(_.toInt)
8 |
9 | println("%.3f".formatLocal(Locale.ENGLISH, arr.count(_ > 0) / n.toDouble))
10 | println("%.3f".formatLocal(Locale.ENGLISH, arr.count(_ < 0) / n.toDouble))
11 | println("%.3f".formatLocal(Locale.ENGLISH, arr.count(_ == 0) / n.toDouble))
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/plus_minus/plus_minus.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_s.to_i
2 | arr = gets.to_s.split(" ").map { |s| s.to_i }
3 | positives = 0
4 | negatives = 0
5 | zeroes = 0
6 | for i in arr do
7 | positives += 1 if i > 0
8 | negatives += 1 if i < 0
9 | zeroes += 1 if i == 0
10 | end
11 |
12 | puts positives / n.to_f
13 | puts negatives / n.to_f
14 | puts zeroes / n.to_f
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/simple_array_sum/SimpleArraySum.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class SimpleArraySum
4 | {
5 | public static void main(String[] args)
6 | {
7 | Scanner stdin = new Scanner(System.in);
8 | final int n = stdin.nextInt();
9 | int sum = 0;
10 | for(int i = 0; i < n; i++)
11 | {
12 | sum += stdin.nextInt();
13 | }
14 | System.out.println(sum);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/simple_array_sum/SimpleArraySum.js:
--------------------------------------------------------------------------------
1 | var sum = 0;
2 | function processData(input) {
3 | var lines = input.split("\n");
4 | var n = parseInt(lines[0]);
5 | var arr = lines[1].split(" ");
6 | for (var i = 0; i < n; i++) {
7 | sum += parseInt(arr[i]);
8 | }
9 | console.log(sum);
10 | }
11 |
12 | process.stdin.resume();
13 | process.stdin.setEncoding("ascii");
14 | _input = "";
15 | process.stdin.on("data", function (input) {
16 | _input += input;
17 | });
18 |
19 | process.stdin.on("end", function () {
20 | processData(_input);
21 | });
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/simple_array_sum/SimpleArraySum.scala:
--------------------------------------------------------------------------------
1 | object SimpleArraySum extends App {
2 | val console = io.Source.stdin.bufferedReader()
3 | val n = console.readLine().toInt;
4 | println(console.readLine().split(" ").map(_.toInt).sum)
5 | }
6 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/simple_array_sum/simple_array_sum.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | arr = gets.split(" ").map { |c| c.to_i }
3 | sum = 0
4 | for i in arr do
5 | sum += i
6 | end
7 | puts sum
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/solve_me_first/SolveMeFirst.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class SolveMeFirst {
4 | static int solveMeFirst(int a, int b) {
5 | return a+b;
6 | }
7 | public static void main(String[] args) {
8 | Scanner in = new Scanner(System.in);
9 | int a;
10 | a = in.nextInt();
11 | int b;
12 | b = in.nextInt();
13 | int sum;
14 | sum = solveMeFirst(a, b);
15 | System.out.println(sum);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/solve_me_first/SolveMeFirst.scala:
--------------------------------------------------------------------------------
1 | object SolveMeFirst {
2 |
3 | def main(args: Array[String]) {
4 | println(io.Source.stdin.getLines().take(2).map(_.toInt).sum)
5 | }
6 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/solve_me_first/solve_me_first.rb:
--------------------------------------------------------------------------------
1 | def solveMeFirst (a, b)
2 | return a+b
3 | end
4 |
5 | val1 = gets.to_i
6 | val2 = gets.to_i
7 | sum = solveMeFirst(val1,val2)
8 | print (sum)
9 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/solve_me_second/SolveMeSecond.scala:
--------------------------------------------------------------------------------
1 | object SolveMeSecond extends App {
2 | val n = readInt
3 | //recommended
4 | (1 to n).map(i => readLine.split(" ").map(_.toInt).sum).foreach(println)
5 |
6 | /*
7 | another way
8 | for (i <- 1 to n) {
9 | val Array(a, b) = readLine.split(" ").map(_.toInt)
10 | println(a + b)
11 | }
12 | */
13 | }
14 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/solve_me_second/solve_me_second.rb:
--------------------------------------------------------------------------------
1 | def solveMeSecond (a, b)
2 | return a+b
3 | end
4 | t = gets.to_i
5 | (0...t).each do |i|
6 | lis = gets.strip.split(" ")
7 | a = lis[0].to_i
8 | b = lis[1].to_i
9 | res = solveMeSecond(a,b)
10 | puts res
11 | end
12 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/staircase/Staircase.scala:
--------------------------------------------------------------------------------
1 | object Staircase extends App {
2 | val n = io.Source.stdin.bufferedReader().readLine().toInt
3 |
4 | Range(1, n + 1).foreach {
5 | i => println(stair(i, n))
6 | }
7 |
8 | def stair(i: Int, n: Int) = " " * (n - i) + "#" * i
9 | }
10 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/staircase/staircase.rb:
--------------------------------------------------------------------------------
1 | def stair(spaces, hashes)
2 | " " * spaces + "#" * hashes
3 | end
4 |
5 | n = gets.to_i
6 |
7 | for i in 1..n do
8 | puts stair(n - i, i)
9 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/time_conversion/TimeConversion.scala:
--------------------------------------------------------------------------------
1 | object TimeConversion extends App {
2 | val line = io.Source.stdin.bufferedReader().readLine()
3 |
4 | val hours = line.substring(0, line indexOf ':').toInt
5 | val minutes = line.substring((line indexOf ':') + 1, line lastIndexOf ':').toInt
6 | val seconds = line.substring((line lastIndexOf ':') + 1, (line lastIndexOf ':') + 3).toInt
7 |
8 | val newHours = if (hours == 12) 0 else hours
9 | val shift = if(line.toLowerCase contains "pm") 12 else 0
10 | println("%02d:%02d:%02d".format((newHours + shift), minutes, seconds))
11 | }
12 |
--------------------------------------------------------------------------------
/HackerRank2/practice/algorithms/warmup/time_conversion/time_conversion.rb:
--------------------------------------------------------------------------------
1 | input_time = gets.to_s
2 | hours = input_time.slice(0, 2).to_i
3 | minutes = input_time.slice(input_time.index(":") + 1, 2).to_i
4 | seconds = input_time.slice(input_time.index(":", input_time.index(":") + 1) + 1, 2).to_i
5 |
6 | newHours = hours
7 | if hours == 12 then
8 | newHours = 0
9 | end
10 |
11 | shift = 0
12 | if input_time.upcase.include? "PM" then
13 | shift = 12
14 | end
15 |
16 | puts "%02d:%02d:%02d" % [newHours + shift, minutes, seconds]
17 |
--------------------------------------------------------------------------------
/HackerRank2/practice/data_structures/arrays/arrays-ds/ArrayDS.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class ArraysDS {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int length = stdin.nextInt();
8 | int[] array = new int[length];
9 | for(int i = 0; i < length; i++) {
10 | array[i] = stdin.nextInt();
11 | }
12 | for(int i = length - 1; i >= 0; i--) {
13 | System.out.print(array[i] + " ");
14 | }
15 | stdin.close();
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HackerRank2/practice/data_structures/arrays/arrays-ds/ArraysDS.scala:
--------------------------------------------------------------------------------
1 | object ArraysDS {
2 |
3 | def main(args: Array[String]) {
4 | val sc = new java.util.Scanner (System.in)
5 | var n = sc.nextInt()
6 | var arr = new Array[Int](n)
7 | for(arr_i <- 0 to n-1) {
8 | arr(arr_i) = sc.nextInt()
9 | }
10 | println(arr.reverse.mkString(" "))
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/data_structures/arrays/arrays-ds/arrays_ds.rb:
--------------------------------------------------------------------------------
1 | n = gets.strip.to_i
2 | arr = gets.strip
3 | arr = arr.split(' ').map(&:to_i)
4 | puts arr.reverse.join(" ")
5 |
--------------------------------------------------------------------------------
/HackerRank2/practice/data_structures/data_structures.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/data_structures/linked_lists/print_the_elements_of_a_linked_list/PrintTheElementsOfALinkedList.java:
--------------------------------------------------------------------------------
1 | /*
2 | Print elements of a linked list on console
3 | head pointer input could be NULL as well for empty list
4 | Node is defined as
5 | class Node {
6 | int data;
7 | Node next;
8 | }
9 | */
10 |
11 | // This is a "method-only" submission.
12 | // You only need to complete this method.
13 |
14 | void Print(Node head) {
15 | while(head != null) {
16 | System.out.println(head.data);
17 | head = head.next;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/ad_hoc/jumping_bunnies/JumpingBunnies.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object JumpingBunnies extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val bunnies = lines(1).split(" ").map(_.toInt)
6 |
7 | val commonPoint = bunnies.foldLeft(BigInt(1))(lcm(_, _))
8 |
9 | println(commonPoint)
10 |
11 | def gcd(x: BigInt, y: BigInt): BigInt = {
12 | if(y == 0) x else gcd(y, x % y)
13 | }
14 |
15 | def lcm(x: BigInt, y: BigInt): BigInt = {
16 | (x * y) / gcd(x, y)
17 | }
18 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/ad_hoc/remove_duplicates/RemoveDuplicates.scala:
--------------------------------------------------------------------------------
1 | object RemoveDuplicates extends App {
2 | println(Console.readLine.distinct)
3 | }
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/ad_hoc/rotate_string/RotateString.scala:
--------------------------------------------------------------------------------
1 | object RotateString extends App {
2 |
3 | val lines = io.Source.stdin.getLines().toList
4 | val n = lines.head.toInt
5 | val strings = lines.tail
6 |
7 | strings.foreach(s =>
8 | println(rotations(s, 0).mkString(" "))
9 | )
10 |
11 | def rotate(s: String): String = {
12 | s.tail + s.head
13 | }
14 |
15 | def rotations(s: String, n: Int): List[String] = {
16 | if(n == s.length) Nil else rotate(s) :: rotations(rotate(s), n + 1)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/array_of_n_elements/ArrayOfN.scala:
--------------------------------------------------------------------------------
1 | object ArrayOfN extends App {
2 |
3 | def f(num: Int): List[Int] = (1 to num).toList
4 |
5 | println(f(readInt).length)
6 |
7 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/evaluating_e^x/EvaluatingEx.scala:
--------------------------------------------------------------------------------
1 | object EvaluatingEx extends App {
2 | def f(x: Double): Double =
3 | {
4 | f2(x, 9)
5 | }
6 |
7 | def fact(x: Int): Int = if (x <= 1) 1 else x * fact(x - 1)
8 |
9 | def f2(x: Double, i: Int): Double =
10 | {
11 | if (i == 0) 1 else Math.pow(x, i) / fact(i) + f2(x, i - 1)
12 | }
13 |
14 | val n = readInt
15 | (1 to n) foreach (x => println(f(readFloat())))
16 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/filter_array/FilterArray.scala:
--------------------------------------------------------------------------------
1 | object FilterArray extends App {
2 |
3 | def f(num: Int, arr: List[Int]): List[Int] = arr.filter(_ < num)
4 |
5 | var lines = io.Source.stdin.getLines.toList
6 | println(f(lines(0).toInt, lines.map(_.trim).map(_.toInt)).map(_.toString).mkString("\n"))
7 |
8 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/filter_positions_in_a_list/FilterPositions.scala:
--------------------------------------------------------------------------------
1 | object FilterPositions extends App {
2 | def f(arr: List[Int]): List[Int] =
3 | arr match {
4 | case x :: y :: l => y :: f(l)
5 | case x :: y => y
6 | case Nil => Nil
7 | }
8 |
9 | println(f(io.Source.stdin.getLines.toList.map(_.trim).map(_.toInt)).mkString("\n"))
10 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/hello_world/HelloWorld.scala:
--------------------------------------------------------------------------------
1 | object HelloWorld extends App {
2 | def f() = println("Hello World")
3 |
4 | f()
5 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/hello_world_n_times/HelloWorldNTimes.scala:
--------------------------------------------------------------------------------
1 | object HelloWorldNTimes extends App {
2 | def f2(i: Int): Unit = println("Hello World")
3 |
4 | def f(n: Int) = (1 to n).foreach(f2(_))
5 |
6 | var n = readInt
7 | f(n)
8 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-evaluating_expressions_1/solution.txt:
--------------------------------------------------------------------------------
1 | 4
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-evaluating_expressions_2/solution.txt:
--------------------------------------------------------------------------------
1 | 6
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-evaluating_expressions_3/solution.txt:
--------------------------------------------------------------------------------
1 | 47
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-evaluating_expressions_4/solution.txt:
--------------------------------------------------------------------------------
1 | 2
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-evaluating_expressions_5/solution.txt:
--------------------------------------------------------------------------------
1 | 0
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-reductions_1/solution.txt:
--------------------------------------------------------------------------------
1 | y
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-reductions_2/solution.txt:
--------------------------------------------------------------------------------
1 | w
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-reductions_3/solution.txt:
--------------------------------------------------------------------------------
1 | CAN'T REDUCE
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/lambda_calculus-reductions_4/solution.txt:
--------------------------------------------------------------------------------
1 | CAN'T REDUCE
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/list_length/ListLength.scala:
--------------------------------------------------------------------------------
1 | object ListLength extends App {
2 |
3 | def f(arr: List[Int]): Int = {
4 | var count = 0
5 | for (i <- arr) count += 1
6 | count
7 | }
8 |
9 | println(f(io.Source.stdin.getLines.toList.map(_.trim).map(_.toInt)))
10 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/reverse_a_list/ReverseList.scala:
--------------------------------------------------------------------------------
1 | object ReverseList extends App {
2 | def f(arr: List[Int]): List[Int] =
3 | (arr.foldLeft(List.empty[Int])((list, e) => e :: list))
4 |
5 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/solve_me_first_fp/SolveMeFirst.scala:
--------------------------------------------------------------------------------
1 | object SolveMeFirst {
2 | def main(args: Array[String]) {
3 | println(io.Source.stdin.getLines().take(2).map(_.toInt).sum)
4 | }
5 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/sum_of_odd_elements/SumOddElements.scala:
--------------------------------------------------------------------------------
1 | object SumOddElements extends App{
2 | def f(arr:List[Int]):Int = arr.filter(_ % 2 != 0).sum
3 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/introduction/update_list/UpdateList.scala:
--------------------------------------------------------------------------------
1 | object UpdateList extends App {
2 |
3 | def f(arr: List[Int]): List[Int] = if (arr.isEmpty) Nil else arr.head.abs :: f(arr.tail)
4 |
5 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/recursion/fibonacci_numbers/FibonacciNumbers.scala:
--------------------------------------------------------------------------------
1 | object FibonacciNumbers {
2 | def fibonacci(x:Int):Int = {
3 | if(x == 1) 0
4 | else if(x == 2) 1
5 | else fibonacci(x - 1) + fibonacci(x - 2)
6 | }
7 |
8 | def main(args: Array[String]) {
9 | println(fibonacci(readInt()))
10 | }
11 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/recursion/pascals_triangle/PascalTriangle.scala:
--------------------------------------------------------------------------------
1 | object PascalTriangle extends App {
2 |
3 | val k = io.Source.stdin.bufferedReader().readLine().toInt
4 |
5 | (0 until k).foreach {
6 | row =>
7 | println(List.range(0, row + 1)
8 | .map(col =>
9 | fact(row) / (fact(col) * fact(row - col)))
10 | .mkString(" "))
11 | }
12 |
13 | def fact(n: Int): Int = {
14 | if(n <= 1) 1
15 | else n * fact(n - 1)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/recursion/string-o-permute/StringOPermute.scala:
--------------------------------------------------------------------------------
1 | object StringOPermute extends App {
2 | val lines = Source.stdin.getLines().drop(1)
3 | val linePairs = lines.map(_.grouped(2).map(_.reverse).toList.flatten)
4 | println(linePairs.mkString("\n"))
5 | }
6 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/recursion/string_mingling/StringMingling.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object StringMingling extends App {
4 | val lines = Source.stdin.getLines().toList
5 | val p = lines.head
6 | val q = lines.tail.head
7 |
8 | val mingled = p.indices.map(i => p(i) + "" + q(i)).mkString("")
9 | println(mingled)
10 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/recursion/string_reductions/StringReductions.scala:
--------------------------------------------------------------------------------
1 | object StringReductions extends App {
2 | println(io.Source.stdin.getLines().toList.head.distinct)
3 | }
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/functional_programming/recursion/super_digit/SuperDigit.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object SuperDigit extends App {
4 | val line = Source.stdin.bufferedReader().readLine()
5 | val nk = line.split(" ")
6 | val n = nk(0)
7 | val k = nk(1).toInt
8 |
9 | println(superDigit(n, k))
10 |
11 | def superDigit(num: String, k: Int): String = {
12 | if(num.length == 1) {
13 | return num
14 | } else {
15 | val sum: BigInt = num.foldLeft(BigInt(0))(_ + Character.digit(_, 10)) * k
16 | return superDigit(sum.toString, 1)
17 | }
18 | }
19 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/java/introduction/java_end-of-file/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | class Solution {
4 | public static void main(String [] args) {
5 | Scanner sc = new Scanner(System.in);
6 | int line = 1;
7 | while (sc.hasNextLine()) {
8 | System.out.println(line ++ + " " + sc.nextLine());
9 | }
10 | sc.close();
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/java/introduction/java_loops_i/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner in = new Scanner(System.in);
7 | int n = in.nextInt();
8 | for(int i = 1; i <= 10; i++) {
9 | System.out.println(n + " x " + i + " = " + (i * n));
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/java/introduction/java_output_formatting/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner sc = new Scanner(System.in);
7 | System.out.println("================================");
8 | for(int i = 0; i < 3; i++){
9 | String s1 = sc.next();
10 | int x = sc.nextInt();
11 | System.out.printf("%-15s%03d\n", s1, x);
12 | }
13 | System.out.println("================================");
14 |
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/HackerRank2/practice/java/introduction/java_stdin_and_stdout_1/JavaStdinAndStdout1.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Solution
4 | {
5 | public static void main(String[] args)
6 | {
7 | Scanner sc=new Scanner(System.in);
8 | int a=sc.nextInt();
9 | int b = sc.nextInt();
10 | int c = sc.nextInt();
11 |
12 | System.out.println(a);
13 | System.out.println(b);
14 | System.out.println(c);
15 | }
16 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/java/introduction/java_stdin_and_stdout_2/Solution.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class Solution {
4 |
5 | public static void main(String[] args) {
6 | Scanner scan = new Scanner(System.in);
7 | int i = scan.nextInt();
8 | double d = scan.nextDouble();
9 | scan.nextLine();
10 | String s = scan.nextLine();
11 |
12 | System.out.println("String: " + s);
13 | System.out.println("Double: " + d);
14 | System.out.println("Int: " + i);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/HackerRank2/practice/java/introduction/welcome_to_java/WelcomeToJava.java:
--------------------------------------------------------------------------------
1 | public class WelcomeToJava
2 | {
3 | public static void main(String []argv)
4 | {
5 | System.out.println("Hello World.");
6 | System.out.println("Hello Java.");
7 | }
8 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/java/strings/strings1.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/bash/a_personalized_echo/a_personalized_echo.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | read name
4 | echo "Welcome $name"
5 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/bash/comparing_numbers/comparing_numbers.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | read x
4 | read y
5 |
6 | if ((x < y)); then
7 | echo "X is less than Y"
8 | elif ((x > y)); then
9 | echo "X is greater than Y"
10 | else
11 | echo "X is equal to Y"
12 | fi
13 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/bash/getting_started_with_conditionals/getting_started_with_conditionals.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | read letter
4 |
5 | if [[ ("$letter" == "y") || ( "$letter" == "Y" ) ]]; then
6 | echo "YES"
7 | elif [[ ("$letter" == "n") || ( "$letter" == "N" ) ]]; then
8 | echo "NO"
9 | fi
10 |
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/bash/lets_echo/lets_echo.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | echo "HELLO"
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/bash/looping_and_skipping/looping_and_skipping.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | for i in {1..99..2}
4 | do
5 | echo $i
6 | done
7 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/bash/looping_with_numbers/looping_with_numbers.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | for i in {1..50}
4 | do
5 | echo $i
6 | done
7 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/bash/the_world_of_numbers/the_world_of_numbers.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | read x
4 | read y
5 |
6 | echo $[$x + $y]
7 | echo $[$x - $y]
8 | echo $[$x * $y]
9 | echo $[$x / $y]
10 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/grep_sed_awk/grep_1/the_grep_command1.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | grep "\bthe\b"
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/grep_sed_awk/grep_2/the_grep_command2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | grep -i "\bthe\b"
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/cut_1/the_cut_command1.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cut -c3
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/cut_2/the_cut_command2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | cut -c2,7
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/head_of_a_text_file_1/the_head_of_text_file1.sh:
--------------------------------------------------------------------------------
1 | #/bin/bash
2 |
3 | head -n 20
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/head_of_a_text_file_2/the_head_of_text_file2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | head -c 20
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/sort_command_1/the_sort_command1.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | sort -n
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/sort_command_2/the_sort_command2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | sort -r
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/tr_command_1/the_tr_command1.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | tr "(" "\[" | tr ")" "]"
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/linux_shell/text_processing/tr_command_2/the_tr_command2.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | tr -d [a-z]
4 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/combinatorics/building_a_list/building_list.rb:
--------------------------------------------------------------------------------
1 | def combine(result, input, start, actual)
2 | for i in start...input.length do
3 | out = actual
4 | actual += input[i]
5 | result << actual
6 | if i < input.length
7 | combine(result, input, i + 1, out);
8 | end
9 | end
10 | end
11 |
12 | test_cases = gets.chomp.to_i
13 | test_cases.times do
14 | length = gets.strip.chomp.to_i
15 | input = gets.strip.chomp.to_s
16 | result = []
17 | combine(result, input, 0, '')
18 | result.sort! {|a, b| a <=> b}
19 | puts result.join("\n")
20 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/combinatorics/picking_cards/picking_cards.rb:
--------------------------------------------------------------------------------
1 | test_cases = gets.chomp.to_i
2 | test_cases.times do
3 | array_length = gets.chomp.to_i
4 | array = gets.chomp.split.map { |e| e.to_i }
5 |
6 | array.sort! { |i,j| j <=> i }
7 |
8 | result = 1
9 | array.each do |element|
10 | diff = array_length - element
11 | diff = 0 if diff < 0
12 | result *= diff
13 | result %= 1000000007
14 | array_length -= 1
15 | end
16 | puts result
17 | end
18 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/connecting_towns/ConnectingTowns.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object ConnectingTowns extends App {
4 | val lines = Source.stdin.getLines().drop(1)
5 | val routesArray = lines.toList.filter(_.contains(" "))
6 | val routes = routesArray.map(_.split(" ").map(_.toLong).foldLeft(1L)(_ * _ % 1234567))
7 | println(routes.mkString("\n"))
8 | }
9 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/connecting_towns/connecting_towns.rb:
--------------------------------------------------------------------------------
1 | cases = gets.chomp.to_i
2 | cases.times do
3 | result = 1
4 | towns = gets.chomp.to_i
5 | routes = gets.chomp.split.map { |e| e.to_i }
6 | for i in 0..towns - 2 do
7 | result *= routes[i]
8 | result %= 1234567
9 | end
10 | puts result
11 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/filling_jars/filling_jars.rb:
--------------------------------------------------------------------------------
1 | (n_jars, operations) = gets.chomp.split.map { |i| i.to_i}
2 | sum = 0
3 | operations.times do
4 | (a, b, candies) = gets.chomp.split.map { |i| i.to_i}
5 | sum += ((b - a + 1) * candies)
6 | end
7 | average = sum.to_f / n_jars
8 | answer = average.floor
9 | puts answer
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/halloween_party/HalloweenParty.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class HalloweenParty {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int tests = stdin.nextInt();
8 | for(int i = 0; i < tests; i++) {
9 | long k = stdin.nextLong();
10 | long horizontal = k / 2;
11 | long vertical = k - horizontal;
12 | System.out.println(vertical * horizontal);
13 | }
14 | stdin.close();
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/halloween_party/HalloweenParty.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object HalloweenParty extends App {
4 | val lines = Source.stdin.getLines()
5 | val slices = lines.drop(1).map(_.toLong)
6 | val result = slices.map(pieces)
7 | println(result.mkString("\n"))
8 |
9 | def pieces(k: Long): Long = {
10 | val horizontal = k / 2
11 | val vertical = k - horizontal
12 | vertical * horizontal
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/halloween_party/halloween_party.rb:
--------------------------------------------------------------------------------
1 | test_cases = gets.chomp.to_i
2 | test_cases.times do |test|
3 | slices = gets.chomp.to_i
4 | horizontal_slices = slices / 2
5 | vertical_slices = slices - horizontal_slices
6 | puts vertical_slices * horizontal_slices
7 | end
8 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/handshake/Handshake.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class Handshake {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int tests = stdin.nextInt();
8 | for(int i = 0; i < tests; i++) {
9 | long handshakes = 0;
10 | int directors = stdin.nextInt();
11 | for(int j = 0; j < directors; j++) {
12 | handshakes += j;
13 | }
14 | System.out.println(handshakes);
15 | }
16 | stdin.close();
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/handshake/Handshake.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object Handshake extends App {
4 | val lines = Source.stdin.getLines()
5 | val directors = lines.drop(1).map(_.toInt)
6 | val handshakes = directors.map(Range(0, _).toList.sum)
7 | println(handshakes.mkString("\n"))
8 | }
9 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/handshake/handshake.rb:
--------------------------------------------------------------------------------
1 | gets.chomp.to_i.times do
2 | directors = gets.chomp.to_i
3 | result = 0
4 | (directors - 1).downto 0 do |handshakes|
5 | result += handshakes
6 | end
7 | puts result
8 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/is_fibo/IsFibo.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object IsFibo extends App {
4 | val lines = Source.stdin.getLines()
5 | val numbers = lines.drop(1).map(BigInt(_))
6 | val fibos = numbers.map(isFibo)
7 | println(fibos.mkString("\n"))
8 |
9 | def isFibo(n: BigInt): String = {
10 | var fib0: BigInt = 0
11 | var fib1: BigInt = 1
12 | while(fib0 <= n) {
13 | if (fib0 == n) return "IsFibo"
14 | val temp: BigInt = fib0
15 | fib0 = fib1
16 | fib1 += temp
17 | }
18 | "IsNotFibo"
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/is_fibo/is_fibo.rb:
--------------------------------------------------------------------------------
1 | def is_fibo(number)
2 | fib0 = 0
3 | fib1 = 1
4 | while fib0 <= number do
5 | return "IsFibo" if fib0 == number
6 | temp = fib0
7 | fib0 = fib1
8 | fib1 += temp
9 | end
10 | return "IsNotFibo"
11 | end
12 |
13 | test_cases = gets.chomp.to_i
14 | test_cases.times do
15 | number = gets.chomp.to_i
16 | result = is_fibo(number)
17 | puts result
18 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/minimum_draws/MinimumDraws.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class MinimumDraws {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int tests = stdin.nextInt();
8 | for(int i = 0; i < tests; i++) {
9 | System.out.println(stdin.nextInt() + 1);
10 | }
11 | stdin.close();
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/minimum_draws/MinimumDraws.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const processData = input => {
4 | console.log(input.split('\n').slice(1).map(i => parseInt(i) + 1).join('\n'));
5 | };
6 |
7 | process.stdin.resume();
8 | process.stdin.setEncoding("ascii");
9 |
10 | var _input = "";
11 | process.stdin.on("data", input => _input += input);
12 | process.stdin.on("end", () => processData(_input));
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/minimum_draws/MinimumDraws.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object MinimumDraws extends App {
4 | val lines = Source.stdin.getLines()
5 | val pairs = lines.drop(1).map(_.toInt)
6 | val draws = pairs.map(_ + 1)
7 | println(draws.mkString("\n"))
8 | }
9 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/fundamentals/minimum_draws/minimum_draws.rb:
--------------------------------------------------------------------------------
1 | tests = gets.chomp.to_i
2 | tests.times do
3 | pairs = gets.chomp.to_i
4 | result = pairs + 1
5 | puts result
6 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/number_theory/number_theory.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/probability/bday_gift/BdayGift.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class BdayGift {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int tests = stdin.nextInt();
8 | long sum = 0;
9 | for(int i = 0; i < tests; i++) {
10 | sum += stdin.nextInt();
11 | }
12 | System.out.format("%.1f", (double) sum / 2);
13 | stdin.close();
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/probability/bday_gift/BdayGift.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | var _ = require('lodash');
4 |
5 | const processData = input => {
6 | let arr = input.split('\n').slice(1).map(i => parseInt(i))
7 | let sum = _.sum(arr);
8 | console.log((sum / 2) + (sum % 2 == 0 ? '.0' : ''));
9 | };
10 |
11 | process.stdin.resume();
12 | process.stdin.setEncoding("ascii");
13 |
14 | var _input = "";
15 | process.stdin.on("data", input => _input += input);
16 | process.stdin.on("end", () => processData(_input));
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/probability/bday_gift/BdayGift.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object BdayGift extends App {
4 | val lines = Source.stdin.getLines().drop(1).map(_.toLong)
5 | printf("%.1f", lines.sum.toDouble / 2)
6 | }
7 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/probability/bday_gift/bday_gift.rb:
--------------------------------------------------------------------------------
1 | balls = gets.chomp.to_i
2 | expected_num = 0
3 | balls.times do
4 | input = gets.chomp.to_i
5 | expected_num += input
6 | end
7 | expected_num /= 2.0
8 | puts "#{format('%.1f', expected_num)}"
9 |
--------------------------------------------------------------------------------
/HackerRank2/practice/mathematics/probability/probability.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/alien_username/AlienUsername.java:
--------------------------------------------------------------------------------
1 | import java.util.Scanner;
2 |
3 | public class AlienUsername
4 | {
5 | public static void main(String[] args)
6 | {
7 | Scanner scanner = new Scanner(System.in);
8 | int testCases = scanner.nextInt();
9 | for (int i = 0; i < testCases; i++)
10 | {
11 | String input = scanner.next();
12 | if(input.matches("[_\\.]\\d+[a-zA-Z]*_?"))
13 | {
14 | System.out.println("VALID");
15 | }
16 | else
17 | {
18 | System.out.println("INVALID");
19 | }
20 | }
21 | scanner.close();
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/alien_username/AlienUsername.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object AlienUsername extends App {
4 | val usernames = Source.stdin.getLines().drop(1)
5 |
6 | println(usernames.map(validateUsername).mkString("\n"))
7 |
8 | def validateUsername(name: String): String = {
9 | if (name.matches("[_\\.]\\d+[a-zA-Z]*_?"))
10 | return "VALID"
11 | else
12 | return "INVALID"
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/alien_username/alien_username.rb:
--------------------------------------------------------------------------------
1 | n = gets.to_i
2 | n.times do
3 | name = gets.to_s.strip
4 | if /[_\.]\d+[a-zA-Z]*_?/ =~ name
5 | puts "VALID"
6 | else
7 | puts "INVALID"
8 | end
9 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/detect_html_tags/DetectHtmlTags.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object DetectHtmlTags extends App {
4 | private[this] val TAG_PATTERN = "<\\s*[a-z0-9]+"
5 |
6 | val lines = Source.stdin.getLines().drop(1)
7 |
8 | val tags = lines.map(parseTags).flatten.toList
9 | val tagsSet = tags.distinct.sorted
10 | println(tagsSet.mkString(";"))
11 |
12 | def parseTags(s: String): Iterator[String] = {
13 | TAG_PATTERN.r.findAllMatchIn(s).map(_.toString).map(_.replaceAll("<", ""))
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/detect_html_tags/detect_html_tags.rb:
--------------------------------------------------------------------------------
1 | require "set"
2 |
3 | lines = gets.chomp.to_i
4 | tags = SortedSet.new
5 | lines.times do
6 | line = gets.chomp.downcase
7 | line.scan(/<\s*[a-z0-9]+/) do |tag|
8 | tags << tag.gsub(/, "")
9 | end
10 | end
11 |
12 | tags_arr = tags.to_a
13 | for i in 0...tags_arr.length - 1 do
14 | print "#{tags_arr[i]};"
15 | end
16 | print "#{tags_arr[tags_arr.length - 1]}"
17 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/detecting_valid_latitude_and_longitude_pairs/valid_latitude_longitude.rb:
--------------------------------------------------------------------------------
1 | gets.chomp.to_i.times do
2 | input = gets.chomp.to_s
3 | if input =~
4 | /^\([+-]?((90(\.0+)?)|([1-8][0-9](\.[0-9]+)?)|([0-9](\.[0-9]+)?)),\s*[+-]?(((([1-9][0-9])|([0-9]))(\.[0-9]+)?)|(1((80(\.0+)?)|([0-7][0-9](\.[0-9]+)?))))\)$/
5 | puts "Valid"
6 | else
7 | puts "Invalid"
8 | end
9 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/find_a_substring/find_substring.rb:
--------------------------------------------------------------------------------
1 | lines_count = gets.chomp.to_i
2 | words = []
3 | lines_count.times do
4 | line = gets.chomp
5 | w = line.split
6 | w.each { |a| words << a}
7 | end
8 |
9 | pattern_count = gets.chomp.to_i
10 | pattern_count.times do
11 | input = gets.chomp
12 | pattern = "[a-z_]+#{input}[a-z_]+"
13 | result = 0
14 | words.each do |word|
15 | if word =~ /\w+#{input}\w+/
16 | result += 1
17 | end
18 | end
19 | puts result
20 | end
21 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/find_hackerrank/FindHackerRank.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object FindHackerRank extends App {
4 | val lines = Source.stdin.getLines().drop(1)
5 | val outputNums = lines.map(findHackerrank)
6 | println(outputNums.mkString("\n"))
7 |
8 | def findHackerrank(line: String): Int = {
9 | if(line.matches("^hackerrank$") || line.matches("^hackerrank.*hackerrank$"))
10 | 0
11 | else if(line.matches("^hackerrank.*"))
12 | 1
13 | else if(line.matches(".*hackerrank$"))
14 | 2
15 | else
16 | -1
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/find_hackerrank/find_hackerrank.rb:
--------------------------------------------------------------------------------
1 | gets.chomp.to_i.times do
2 | input = gets.chomp.to_s
3 | if input =~ /^hackerrank$/ || input =~ /^hackerrank.*hackerrank$/
4 | puts "0"
5 | elsif input =~ /^hackerrank.*/
6 | puts "1"
7 | elsif input =~ /.*hackerrank$/
8 | puts "2"
9 | else
10 | puts "-1"
11 | end
12 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/hackerrank_tweets/HackerrankTweets.java:
--------------------------------------------------------------------------------
1 | import java.util.*;
2 |
3 | public class HackerrankTweets {
4 |
5 | public static void main(String[] args) {
6 | Scanner stdin = new Scanner(System.in);
7 | int tests = Integer.parseInt(stdin.nextLine());
8 | int count = 0;
9 | for(int i = 0; i < tests; i++) {
10 | if(stdin.nextLine().toLowerCase().matches(".*hackerrank.*")) {
11 | count++;
12 | }
13 | }
14 | System.out.println(count);
15 | stdin.close();
16 | }
17 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/hackerrank_tweets/HackerrankTweets.js:
--------------------------------------------------------------------------------
1 | 'use strict';
2 |
3 | const processData = input => {
4 | let lines = input.split('\n').slice(1);
5 | let matches = lines.filter(line => line.toLowerCase().match(/.*hackerrank.*/));
6 | console.log(matches.length);
7 | };
8 |
9 | process.stdin.resume();
10 | process.stdin.setEncoding("ascii");
11 |
12 | var _input = "";
13 | process.stdin.on("data", input => _input += input);
14 | process.stdin.on("end", () => processData(_input));
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/hackerrank_tweets/HackerrankTweets.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object HackerrankTweets extends App {
4 | val lines = Source.stdin.getLines().drop(1)
5 | val matchingLines = lines.count(_.toLowerCase.matches(".*hackerrank.*"))
6 | println(matchingLines)
7 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/hackerrank_tweets/hackerrank_tweets.rb:
--------------------------------------------------------------------------------
1 | tests = gets.chomp.to_i
2 | result = 0
3 | tests.times do
4 | words = gets.chomp.split
5 | words.each do |word|
6 | result += 1 if word.downcase =~ /.*hackerrank.*/
7 | end
8 | end
9 |
10 | puts result
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/ip_address_validation/ip_address_validation.rb:
--------------------------------------------------------------------------------
1 | tests = gets.chomp.to_i
2 | tests.times do
3 | input = gets.chomp.to_s
4 | if input =~ /\b(((2[0-5][0-5])|(1[0-9][0-9])|(\b[1-9][0-9]\b)|(\b\d\b))\.){3}((2[0-5][0-5])|(1[0-9][0-9])|(\b[1-9][0-9]\b)|(\b\d\b))\b/
5 | puts "IPv4"
6 | elsif input =~ /([a-f0-9]{1,4}:){7}\b[0-9a-f]{1,4}\b/
7 | puts "IPv6"
8 | else
9 | puts "Neither"
10 | end
11 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/split_the_phone_numbers/SplitPhoneNumber.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object SplitPhoneNumber extends App {
4 |
5 | private[this] val SPLIT_PATTERN = " |\\-"
6 |
7 | val numbers = Source.stdin.getLines().drop(1)
8 |
9 | numbers.foreach(num => {
10 | val splits = num.split(SPLIT_PATTERN)
11 | println(s"CountryCode=${splits(0)},LocalAreaCode=${splits(1)},Number=${splits(2)}")
12 | })
13 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/split_the_phone_numbers/split_phone_numbers.rb:
--------------------------------------------------------------------------------
1 | tests = gets.chomp.to_i
2 | tests.times do
3 | (country_code, local_area, number) = gets.chomp.split(/ |\-/)
4 | puts "CountryCode=#{country_code},LocalAreaCode=#{local_area},Number=#{number}"
5 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/the_british_and_american_style_of_spelling/american_english_spelling.rb:
--------------------------------------------------------------------------------
1 | lines = gets.chomp.to_i
2 | all_words = []
3 | lines.times do
4 | words = gets.chomp.split.map { |s| s.to_s }
5 | words.each { |w| all_words << w}
6 | end
7 |
8 | tests = gets.chomp.to_i
9 | tests.times do
10 | us_word = gets.chomp.to_s
11 | uk_word = us_word.sub("ze", "se")
12 | count = 0
13 | all_words.each do |word|
14 | count += 1 if word == us_word || word == uk_word
15 | end
16 | puts count
17 | end
18 |
19 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/valid_pan_format/ValidPanFormat.scala:
--------------------------------------------------------------------------------
1 | import scala.io.Source
2 |
3 | object ValidPanFormat extends App {
4 |
5 | private[this] val PAN = "[A-Z]{5}\\d{4}[A-Z]"
6 |
7 | val lines = Source.stdin.getLines().drop(1)
8 | val pans = lines.map(isPan)
9 | println(pans.mkString("\n"))
10 |
11 | def isPan(s: String): String = {
12 | if(s.matches(PAN)) {
13 | "YES"
14 | } else {
15 | "NO"
16 | }
17 | }
18 | }
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/applications/valid_pan_format/pan_format.rb:
--------------------------------------------------------------------------------
1 | tests = gets.chomp.to_i
2 | tests.times do
3 | input = gets.chomp.to_s
4 | if input =~ /[A-Z]{5}\d{4}[A-Z]/
5 | puts "YES"
6 | else
7 | puts "NO"
8 | end
9 | end
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/character_class/excluding_specific_characters/solution.txt:
--------------------------------------------------------------------------------
1 | ^[^\d][^aeiou][^bcDF][^\s][^AEIOU][^\.,]$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/character_class/matching_range_of_characters/solution.txt:
--------------------------------------------------------------------------------
1 | ^[a-z][1-9][^a-z][^A-Z][A-Z]
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/character_class/matching_specific_characters/solution.txt:
--------------------------------------------------------------------------------
1 | ^[123][120][xs0][30Aa][xsu][\.,]$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/grouping_and_capturing/alternative_matching/solution.txt:
--------------------------------------------------------------------------------
1 | ^(Mr|Mrs|Ms|Dr|Er)\.[a-zA-Z]+$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/grouping_and_capturing/capturing_non-capturing_groups/solution.txt:
--------------------------------------------------------------------------------
1 | .*(ok){3}.*
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/grouping_and_capturing/matching_word_boundaries/solution.txt:
--------------------------------------------------------------------------------
1 | \b[aeiouAEIOU][a-zA-Z]*\b
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/introduction/matching_anything_but_a_newline/solution.txt:
--------------------------------------------------------------------------------
1 | ...\....\....\....
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/introduction/matching_digits_non-digit_characters/solution.txt:
--------------------------------------------------------------------------------
1 | \d\d\D\d\d\D\d\d\d\d
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/introduction/matching_specific_string/solution.txt:
--------------------------------------------------------------------------------
1 | hackerrank
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/introduction/matching_start_end/solution.txt:
--------------------------------------------------------------------------------
1 | ^\d\w\w\w\w\.$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/introduction/matching_whitespace_non-whitespace_character/solution.txt:
--------------------------------------------------------------------------------
1 | \S\S\s\S\S\s\S\S
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/introduction/matching_word_non-word_character/solution.txt:
--------------------------------------------------------------------------------
1 | \w\w\w\W\w\w\w\w\w\w\w\w\w\w\W\w\w\w
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/repetitions/matching_ending_items/solution.txt:
--------------------------------------------------------------------------------
1 | ^[a-zA-Z]*e?s$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/repetitions/matching_one_or_more_repetitions/solution.txt:
--------------------------------------------------------------------------------
1 | ^\d+[A-Z]+[a-z]+$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/repetitions/matching_x_repetitions/solution.txt:
--------------------------------------------------------------------------------
1 | ^[a-zA-Z02468]{40}[13579\s]{5}$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/repetitions/matching_xy_repetitions/solution.txt:
--------------------------------------------------------------------------------
1 | ^\d{1,2}[a-zA-Z]{3,}\.{0,3}$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/regex/repetitions/matching_zero_or_more_repetitions/solution.txt:
--------------------------------------------------------------------------------
1 | ^\d{2,}[a-z]*[A-Z]*$
2 |
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/higher_than_75_marks/higher_than_75_marks.sql:
--------------------------------------------------------------------------------
1 | select name from
2 | (
3 | select name, substr(name, length(name)-2) as sub_name
4 | from Students
5 | where marks > 75 order by sub_name, id asc
6 | );
7 |
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/japanese_cities_detail/japanese_cities_detail.sql:
--------------------------------------------------------------------------------
1 | select * from City where CountryCode = 'JPN';
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/japanese_cities_names/japanese_cities_names.sql:
--------------------------------------------------------------------------------
1 | select Name from City where CountryCode = 'JPN';
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/revising_the_select_query-1/revising_the_select_query_1.sql:
--------------------------------------------------------------------------------
1 | Select * from City
2 | where CountryCode='USA' and population > 100000;
3 |
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/revising_the_select_query-2/revising_the_select_query_2.sql:
--------------------------------------------------------------------------------
1 | Select name from City
2 | where CountryCode='USA' and population > 120000;
3 |
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/select_all/select_all.sql:
--------------------------------------------------------------------------------
1 | select * from City;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/select_by_id/select_by_id.sql:
--------------------------------------------------------------------------------
1 | select * from City where ID = 1661;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_1/weather_observation_station_1.sql:
--------------------------------------------------------------------------------
1 | select city, state from station order by city asc, state asc;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_10/weather_observation_station_10.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where
4 | substr(lower(city), length(city), 1) not in ('a', 'e', 'i', 'o', 'u')
5 | order by city;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_11/weather_observation_station_11.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where
4 | substr(lower(city), 1, 1) not in ('a', 'e', 'i', 'o', 'u')
5 | or
6 | substr(lower(city), length(city), 1) not in ('a', 'e', 'i', 'o', 'u')
7 | order by city;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_12/weather_observation_station_12.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where
4 | substr(lower(city), 1, 1) not in ('a', 'e', 'i', 'o', 'u')
5 | and
6 | substr(lower(city), length(city), 1) not in ('a', 'e', 'i', 'o', 'u')
7 | order by city;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_3/weather_observation_station_3.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where
4 | MOD(id, 2) = 0
5 | order by city asc;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_4/weather_observation_station_4.sql:
--------------------------------------------------------------------------------
1 | select num - num_uniq
2 | from (
3 | select count(city) as num, count(distinct city) as num_uniq
4 | from station
5 | );
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_5/weather_observation_station_5.sql:
--------------------------------------------------------------------------------
1 | select * from
2 | (
3 | select city, length(city)
4 | from station
5 | order by length(city) asc, city asc
6 | )
7 | where rownum = 1
8 | union
9 | select * from
10 | (
11 | select city, length(city)
12 | from station
13 | order by length(city) desc, city asc
14 | )
15 | where rownum = 1;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_6/weather_observation_station_6.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where lower(substr(city, 1, 1)) in ('a', 'e', 'i', 'o', 'u')
4 | order by city asc;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_7/weather_observation_station_7.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where
4 | substr(lower(city), length(city), 1) in ('a', 'e', 'i', 'o', 'u')
5 | order by city;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_8/weather_observation_station_8.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where
4 | substr(lower(city), 1, 1) in ('a', 'e', 'i', 'o', 'u')
5 | AND
6 | substr(lower(city), length(city), 1) in ('a', 'e', 'i', 'o', 'u')
7 | order by city;
--------------------------------------------------------------------------------
/HackerRank2/practice/sql/basic_select/weather_observation_station_9/weather_observation_station_9.sql:
--------------------------------------------------------------------------------
1 | select distinct city
2 | from station
3 | where lower(substr(city, 1, 1)) not in ('a', 'e', 'i', 'o', 'u')
4 | order by city asc;
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/Balloon/Image from iOS (1).jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/Balloon/Image from iOS (1).jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/Balloon/Image from iOS.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/Balloon/Image from iOS.jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/Jacob'sFavoriteNumber.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/Jacob'sFavoriteNumber.png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/image (2).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/image (2).png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/image (3).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/image (3).png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/image (4).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/image (4).png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/part1of1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/JacobsFavoriteNumber/part1of1.png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/MakingAnagram/ProblemDescription.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/MakingAnagram/ProblemDescription.png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/MakingAnagram/SampleCases.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/MakingAnagram/SampleCases.png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/Minumum_Moves/image (2).png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/Minumum_Moves/image (2).png
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (1).jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (1).jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (2).jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (2).jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (3).jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (3).jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (4).jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (4).jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (5).jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS (5).jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/q6_7/Image from iOS.jpg
--------------------------------------------------------------------------------
/HackkerRank/src/test/java/JavaQuestions/q8/phpw391F4.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/mehmetgul/JavaInterviewQuestions/9e034179c88437e44e37a629e1b42b0d9fb2f275/HackkerRank/src/test/java/JavaQuestions/q8/phpw391F4.png
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # JavaInterviewQuestions
2 | ## Please don't update the working solutions.
3 | ## Just create new solution under same package.
4 |
--------------------------------------------------------------------------------