Solutions to HackerRank 30Days Challenge in Python 3
I hope this repo could help anyone who find this solutions. Also comments or improvements would be apreciated. This is only for learning purposes. Problems made by their Authors on HackerRank.
Here we go!
No problem with this
Simple maths
Attention to your conditional statements, also interesting to check how to implement multime conditions on the same statement.
if all( [cond1 == 'val1', cond2 == 'val2', cond3 == 'val3', cond4 == 'val4'] ):
if any( [cond1 == 'val1', cond2 == 'val2', cond3 == 'val3', cond4 == 'val4'] ):
From S.Lott on Stack Overflow
I learned that you can set conditions over the initial properties just after their declarations. Also practice on conditionals
Easy maths and loops on Python. Iterables are very interesting. Lists, Tuples, dictionaries and sets are iterables. All have a iter() method
Good practice on string slices
Appliying slice and string to list methods
First take on Dictionaries, but it forces you to find about error handling, that is a tip to manage unknown numbers of inputs.
Not much to say, basics of recursion
Looks simple at first but had to spend some time thinking how to count the max of ones
Good exercise to handle matrix index
Just declaration of sub class, but good example to keep things simple
Abstract Classes could have a constructor and methods. There are serveral ways to implement empty methods.
Two loop cycles that check abs diference between elements and keep the max.
The most important thing is to understand how to traverse a linked list.
In this case, when the input type is wrong, the type of error is ValueError
Important use, an exception could be raised from a Class and be used over the main program
Stacks are normal lists with propper care, queues came from collections, and remember to use popleft, not pop.
Important to learn about Abstract Classes and Interfaces. Python only have Abstract classes, Java uses Interfaces for multiple inheritance.
Implementantion of Bubble Sort
Only file on C++. Generics was not available on Python, but you only need to undestand the logic of generics, which means a single function or class who could recive different type of inputs. Also important how to print statements on C++.
Have to find the height of trees, which is the definition.
The key is using a queue, understanding data structures. This is Breadth First Search
Had to fight for a while with edge cases, is not hard but thing about several repeated values.
You should always try to understand the algorithm before trying to code it. Why O(n**0.5)?. That's always lower than O(n)
Beware of edge cases, logic is simple but keep in mind end of months and other special cases
Important to understand the meaning of the test, you just have to be clear with the results you want.
Not so much about databases but simple example of Regex.
This was a genuine surprise, logic by brute force is simple, but you should try it and later improve it. There is a elegant solution to this problems. I had to look for this solution which only improves runtime but is not the best. The road is just beggining.