Day 0-9 of 30 Days of code @ HackerRank

You are fully capable of deciding your destiny. The only question is what will you choose to be.

— Spock’s father

So , I started HackerRank’s 30 Days of Code because I had to start learning Java and it was damn interesting and I am happy that I learned soo much through these contents and I think a lot of the credit would go to the amazing video lessons from Kathryn Hodge (@blondibytes) and even though I was able to complete 10 day’s work in just 4 days but I feel guilty of not doing anything in the past 2 days , which is absolutely unprecedented as I code for at least 6 days . Here’s the Github repository to the code of the 10 days –

So , I have covered the following concepts in these 10 lessons –

  1. Class , fields and methods . Syntax of class –

class <class_name> {

<dataType1> <fieldName1>;

<dataType2> <fieldName2>;


<dataTypeN> <fieldNameN>;

<modifier1> <modifierName1>(<dataType1> <pName1>,…,<dataType1> <pName1>) { <method_block> }


<modifierN> <methodNameN>(<dataType1> <pName1>,…,<dataType1> <pName1>) { <method_block> }

2. Naming convention for classes : Should begin with Capital letters and for conjunction of multiple phrases it should follow CamelCase (e.g. birthOfDate , buildDate ) or Lower snake case (e.g. Student_Class).

3. Concept of variable and it’s naming convention : Should begin with small letter and should follow CamelCase in case of conjunction of multiple words. (e.g. dateOfBirth).It shouldn’t have spaces or any special character other than _ and it shouldn’t begin with a number. variable of a class is called a field.

4. Java as a statically typed language and declaration & initialization of data type for a variable :-

<DataTypeName> variableName = <value>;

Initialization is possible because of assignment “=” operator , which assigns value on RHS to LHS (which is the variable).

5. Functions as a sequence of instructions to perform a given task. Syntax of function :-

<modifier> <dataType/void> functionName(<dType1> var1 , …… ,<dTypeN> varN)

{ <function_block> }

6. Methods are just functions of a class & objects are instances of a class.

7. Scanner class for accepting input . Different scanner class methods –


next<name>() where <name>=BigDecimal , BigInteger , Boolean , Byte , Double , Float , Int , Line , Long , Short

Initialization of scanner class –

Scanner <objectName> = new Scanner ( );

8. Difference between next() and nextLine().

9. Class for the purpose of abstraction.

10. Primitive data type (int , double , float , boolean , char).

11. Statement terminator and it’s use .

12. Boolean data type and the values it can store.

13. Public scope of a function & void modifier.

14. Creating instance of any given class :-

ClassName objectName = new ClassName(); //Default

ClassName objectName = new ClassName(value1 , value2 , … , valueN); //Parammetrized

Calling non-static method of a given class’s object –


objectName.methodName(value1 , value2 , …. , valueN );

15. Difference between print() , printf() and println() .

16. Class as a reference data type . other example of referenced data type is Arrays , Linked lists , Stacks , Queues , … etc

17. Reference data type vs Primary data type.

18. What is a data type ? It defines , stores and restricts what given value can be stored in a given variable.

19. Primitive data types : byte , short , int , long , float , double , boolean and char .

20. String class and it’s objects .

21. use of scannerObjectName.close()

22. Assigning default values to fields of a class through assignment after declaration.

<modifier> ClassName

{ <dataType> fieldName = <value>; }

23. Default constructors are created by the compiler which assigns default values to the fields (if the fields are present in the class) , but they can also be specified by the programmer . Here’s how to do it –

public ClassName() {

this.fieldName1 = pSpecifiedValue1;

this.fieldName2 = pSpecifiedValue2;


this.fieldNameN = pSpecifiedValueN;


24. A parameter for a function is basically the input a function receives from the user. Syntax for a parametrized constructor

public ClassName (<dataType1> <value1> , ….. ,<dataTypeN> <valueN>) {

this.fieldName1 = <value1> ;


this.fieldNameN = <valueN> ; }

25. A return statement , returns back the value for a given method or a function.

NOTE – It is compulsory to either assign void or data type for the data type.

26. Re-usability of classes.

27. Types of operators based on no of operands : Unary , binary and ternary .

28 Basic arithmetic operators : + – * / %

Additional operators : + (as String concatenation) , ++ (post/preincrementation) , — (post/predecrementation) , ! (negation) , == (equality comparison) , != (non-equality comparison) , <= >= < > (comparison operators) , && || (logical AND OR) , ? : (if-then-else) .

29. Difference between classes and objects .

30. if-else statements allow to control the flow of execution based on certain conditions. Syntax of if-else statements –

if (<testCondition>)

{ <ifBlock> }


{ <elseBlock> }

In this case <ifBlock> would be executed when <testCondition> gives true as boolean output otherwise <elseBlock> would be executed.

31. Importing and object declaration of Random class , which is used to obtain random numbers –

Importing : import java.util.Random;

Declration : Random randomObjectName = new Random();

Generating random integer : randomObjectName.nextInt();

32. Accessing absolute value :

Math.abs(<value>); /*Value should be a number , no import required , output is +ve*/

33. Logical operators : || (Logical disjunction) , && (Logical conjunction) & ! (negation)

34. Ternary expressions :-

<expression> ? <output1> : <output2>

if <expression> is true <output1> is considered otherwise <output2> is considered. This is similar to if-else.

35. Switch-case condition : Quite useful when it comes to multiple-decision branching. Syntax of the switch-case statements –

switch (<testValue>) {

case val0:




case valN:







In this case a testValue has to be passes to switch and behavior has to be specified for case and default case is to be provided in the condition when no other cases have been specified.

36. Static methods and fields of a class can be called from main function without declaring object for the provided class , this is because main() itself is a static method. Calling a non-static method from main() isn’t possible.

37. this is a reference variable which points to the currently used object.

e.g. for a class className , which has a method methodName , so we can call the method for the given class by this.methodName() or for a field fieldName , we could call the provided field by using this.fieldName.

38. Getter method is used to return the value of a field for a given object. Syntax of getter method :-

public <dataType> getFieldName()

{ return this.fieldName; }

39. Setter method is used to set the value for a given field of a class’s object. Syntax of setter method :-

public void setFieldName(<dataType> newFieldName)

{ this.fieldName=newFieldName; }

40. Boolean operators are operators which deals with boolean values (true/false).

A && B := true only when both expressions A and B are true

A || B := true only when either of expressions A or B are true

! C := true only when expression C is false

A != B := true only when value A is not true to value B

41. Class method is a method of a class which is static , so it can called without declaring object for a given function.

42. Method for accepting a character as input –;

43. While loop is a block of code which is executed repeatedly under some condition. Syntax of do-while loops :-

while (<condition>)

{ <while_block> }

44. Do-while loop is a loop similar to while loop , but here a block of statement is executed first and then the while block’s condition is tested –

do { <do_block> }

while (<condition>);

45. Scope of a local variable is limited to a given block.

46. For loop allows looping through initialization (which involves declaration of local variables), termination condition and incrementation condition :-

for(<dataType> variableName = <initialCondition> ; variableName><operator><terminationCondition>; <variableIncrementer> )

{ <forBlock> }

47. Break statement allows to break the loop even when the loop’s test-condition is satisfied. They should be called under certain condition –

if ( <testCondition> )

{ break; }

48. Nested for loops : For loops within for loops

49. Arrays are collections of homogeneous data type. They are a container object which could store a fixed number of values for any given data type.

50. Iteration : Passing through each element of java.

51. A container object is a class or a data structure whose instances are a collection of other objects.

52. Declaration of an array and allocation of it’s size :-

<dataType>[] <arrayName> = new <dataType>[<size>]

In case of an array , the size is fixed , it cannot change.

53. Every class in java is a child of object class , either directly or indirectly. toString() is a method which is used to represent the element of Array class. Method to print out values of a given array –

System.out.println( Arrays.toString( <arrayName> ) );

54. Statements for allocation , declaration and initialization of an array –

<dataType>[] <arrayName>; //Declaration

<dataType>[] <arrayName> = new <dataType>[<size>]; //Declaration & Allocation

//Declaration , Initialization & Allocation

<dataType>[] <arrayName> ={<val1>, ….. , <valN>};

55. Default value of int , float/double and string is 0 , 0.0 and none respectively.

56. Array as a reference data structure.

57. arrayName[<position>] can be used to extract individual elements of an array. If the <position> > the length of the array then a null pointer would be returned and there would be an indexError .

58. Syntax for sorting an array :-


Using the above sort() of Arrays would change the original order of the array forever.

59. Syntax of for-each loop :-

for( <dataType> <varName> : <arrayName> )

{ System.out.println(<varName>) }

this is similar to python’s for e in arrayName statement.

Array class can be imported by :- import java.util.Array;

60. Dictionary is a container data type of variable length which stores data by using key and value pairs , where an key-value can be inserted or deleted. This is quite contrary to the array data type which has fixed size. Dictionary is an abstract data type and it doesn’t exist directly similar to Arrays , rather it is created by mapping .

Key —– > Value (Key to value mapping)

61. Statement to create mapping –

Map < WDataType1 , WDataType2 > nameOfDictionary = new HashMap <WDataType1 , WDataType2 >();

Where the data type of key as well as value should be of wrapper class.

To use the above statements we can use –

import java.util.Map;

import java.util.HashMap;

62. Statement to add values to dictionary –

nameOfDictionary.put( keyN , valueN );

63. Statement to extract values based on keys –

nameOfDictionary.get( key1 );

64. Statement to extract keyset –

nameOfDictionary.keySet( );

65. Statement to extract value set –

nameOfDictionary.values( );

66. Statement to extract size of the dictionary –

nameOfDictionary.size( );

67. Wrapper classes are classes whose object wraps and is used to store primitive object. When the objects for this class is initialized then it’s method stores the value of primitive data type. Data type declaration for Wrapper class data types –

char — Character byte — Byte short — Short

long — Long float — Float double — Double

boolean — Boolean

68. Syntax to print the entire dictionary –

System.out.println( nameOfDictionary.toString() );

This is possible because the Map class is part of object class and so it’s object can be printed by toString()

69. Syntax to clear the entire dictionary –

nameOfDictionary.clear() ;

70. To check whether the entire dictionary is empty or not –

System.out.println( nameOfDictionary.isEmpty() );

71. To remove an element from the dictionary based on key value –

nameOfDictionary.remove(<key>,value) ;

72. Recursion is a process of repeating the an algorithm again and again by calling the function again and again until the base condition isn’t satisfied.

73. Base condition is the condition at which repetition of an algorithm would stop and Recursive condition is the condition in which recursion would continue.

74. Class variables are special attributes of classes . In java they can be declared by using static keyword. Class variable and class method is synonymous with static variable and method. The value of a class variable isn’t dependent on the instance.

75. Instance variables are variables whose value is dependent on the instance or the object of the class.

76. Scope of static variables is global and so it cannot be declared within any method.

77. Constructor overloading : A way to overload a constructor.

78. Argument : Value passed as an argument.

79. Strings use ” ” & characters use ‘ ‘.

80. Explicit typecasting of variable to another can be done by –

(dataType) variableName ;

81. Statement to convert a string to a character array –

char[] charArrayName = stringName.toCharArray();

82. Data structures are a way of organizing data into efficient storage and retrieval.

83. arrayName.length is used extract the value of array’s length or dimension.

Okay , this turned out to be the longest log I have ever written. May be I will try to break down the logs of 5 lessons from next time.

How I learned python and developed a basic functional search engine in 15 days

You will never fulfill your destiny , until you let go of the illusion of control.

–  Master Oogway

Okay , so today I entered the 15th day into learning the fundamentals of computation using python and developing a basic functional search engine along the way. Well by functional , in any way I am not comparing what I have built ,to the likes of Googles and Bings of the world , but even Google search engine is based upon the fundamental concepts which I have used to build my search engine , but in a much much much larger scale and with many more servers just dedicated for the job of crawling and indexing of data.

Contribution graph from my github profile
Contribution graph from my github profile

Along the way I have covered topics like procedures , mutable data types like lists , string handling , string operations (like find() , len() , <string>[::-1]) , link extraction , Backus-Naur Form (BNF) grammar , control statements , loops , multiple assignment , nested lists , list operations (like append() , max() , min() , index() , <value> in/not in <list> , pop()) and many more ideas ranging from ethical programming to problem solving procedure.

And after learning soo much , I realized that a basic search engine was more easier to build , than what I had previously imagined , because you only need a few concepts to build a web crawler (which is the most important part of the search engine) , which is a program which basically collects all the hyperlinks from the web and the only other thing you need , to build a basic search engine is an index list , which is a list of keywords and URLs.

(For people unfamiliar with python , list is a concept similar to arrays in C/C++/Java but it is also miles apart in other functionalities . For example – Arrays are always made up of homogeneous data types , an array of integer cannot contain characters or floating points numbers , but a list like this – [1, 1.2 , ‘a’ , [ 3 , 4 ] ] , is possible in python which makes lists a bazillion times more powerful than array in terms of usability).

So , the very first step to build a web crawler is based upon knowing about anchor tag which is used to create a hyperlink in a html document and it’s syntax is –

<a href=”URL”> link text </a>

The only part we should be interested in is –

<a href=”

Because we have to extract to URL in between the two quotes in href attribute of <a>. So , how to extract it ? Simple , just use find() function , which searches for a target string in a given search string and the syntax of find is –


The find() procedure also comes with one more parameter which could allow to search the target string in the search string after the nth position


So now let’s assume that any given web page’s source code is stored in form of a string variable (e.g. page). Then we could use the following steps to extract the first hyperlink

page = ‘<web page source code>’

start_position = page.find ( ‘<a href =’ )

start_quote = page.find ( ‘ ” ‘ , start_position )     #Will search for 1st quotation mark

start_quote = page.find ( ‘ ” ‘ , start_quote+1 )     #Will search for last quotation mark

url = page[ start_quote+1 : end_quote ]               #Will store URL

And bang , we have extracted our first hyperlink from scratch by just playing around with strings.So, What’s the next step ? Extract all hyperlinks from a given page by just using while loops. But the story of web crawler doesn’t ends here, as you have to extract all hyperlinks from all the web pages your web crawler comes across and this requires a little bit more programming and 2 more variables – tocrawl (which is a list which would contain all the links to be crawled by your web crawler) and crawled (which is a list of all the hyperlinks your web crawler has crawled through). So let’s make the most basic version of web crawler. Seed page is the first page from which the crawling begins. It’s denoted as seed in the following program (Sorry for the indentation error) –

def web_crawler( seed ):

tocrawl = [ seed ]                                                  #As no pages have been crawled yet

crawled=[]                                                             #List of crawled pages

while tocrawl :                                                      #Will run till tocrawl isn’t empty

page=tocrawl.pop()                                        #Extracts last element of tocrawl

content=get_page( page )                              #Source code of page in content

union( tocrawl , get_all_links ( content ) ) #Will do set union of the two lists

crawled.append( page )

return crawled

So, basically what happens in the above program is that ,  the web_crawler procedure or function accepts seed as it’s input , where seed is the seed URL and then stores it in tocrawl , because seed page is to be crawled by the program. Then the last element of tocrawl is popped and stored in a variable ‘page’ and in the first case the last element of tocrawl is seed URL itself and then the next step is to store all the contents of the source code of the web page of the popped element in a variable ‘content’ and after that we could do the set union of the sets of tocrawl and all the extracted hyperlinks from the popped URL (Here union isn’t a predefined function , I had to create it for this purpose alone , but it’s functionality is same as that of set union ). Then the popped page can be appended into crawled list. This process goes on till we have exhausted all the links in tocrawl list , but this process can also be restricted by using 2 parameters – max_depth and max_pages .

The last part of making a basic functional search engine is adding an index list which will store all the contents of the web page which would include the keyword which could be searched from the index.

Here’s the full program for doing so.


Lesson 10-14: Intro to Computer science program (Udacity)

There are no accidents.

– Master Oogway

Okay , this was perhaps the toughest unit , I have come across because it was way too long , but it was also too much fun learning new concepts and improving my web crawler with a few more specifications. The problems from the problem set were also generally tougher than other problem sets. To be honest , the only problem I wasn’t able to solve entirely was Lesson 14’s Quiz 3 : Numbers in the list , It almost worked except for one condition.

Here are the links for for code of each lesson –
Lesson 10 :
Lesson 11 :
Lesson 12 :
Lesson 13 : 14 :

So , these are some of the topics I have learned are:

  1. Solutions of a given computational problem , as a procedure with a set of given inputs and outputs
  2. What is defensive programming ?
  3. 5 basic steps for solving a problem.
  4. What is algorithmic pseudo-code ?
  5. What is a simple mechanical solution ?
  6. What is assertion statement ? What is it’s syntax ?
  7. What is a list ?
  8. What is the difference between lists and strings ?
  9. What is a nested list ?
  10. String as a structured data.
  11. How to access elements of a nested list ?
  12. What is exponentiation operator (**) ?
  13. What is the difference between string’s assignment and list’s mutation ?
  14. What is meant by aliasing ?
  15. Passing mutable data vs non-mutable data as elements of function ?
  16. what is <list>.append(<element>) ?
  17. What is len(<list>) ?
  18. What is list addition ?
  19. What are the basic requirements of storage of data ?
  20. What is latency and latency distance ?
  21. What is DRAM ?
  22. What is a for loop ? What is it’s syntax ?
  23. What is <list>.index(<element>) ?
  24. What is <value> in <list> ? What is <value> not in <list> ?
  25. What is <list>.pop() ?
  26. What role does robot.txt play when it comes to search engine ?
  27. for loop with multiple names.
  28. Building web crawler program with max_depth and max_pages
  29. What is a frequency analyzer ?
  30. What is <list>.reverse() ?

I would perhaps start Unit 4 (Lesson 15-17) by today itself . It will be fun.

Lesson 5-9: Intro to Computer science program (Udacity)

You are too much concerned about what was and what will be. There’s a saying that yesterday is history , tomorrow is mystery , but today is a gift . That’s why it’s called “present”.

– Master Oogway

Completing these lessons was a roller coaster ride for me , because I got stuck at a problem in one of the problem set and I was frustrated , but at the end I solved the problem all on my own and that was a big victory for me. I am now fully committed to learn CS in entirety.

Here are the links for for code of each lesson (except for lesson 9) –
Lesson 5 :
Lesson 6 :
Lesson 7 :
Lesson 8 :

So , these are some of the topics I have learned are:

  1. What is a procedure ?
  2. What are control structures ?
  3. What is procedural abstraction ? How to make it happen ?
  4. What is syntax of a procedure ?
  5. What are parameters ?
  6. What is a block ?
  7. What is a return statement ?
  8. What are procedural side-effects ?
  9. Functions with no return statement & output when such functions are called
  10. Numbers as branching condition / test condition
  11. Localized nature of variables in procedure block
  12. What is procedure composition ?
  13. What are comparison operators ?
  14. What is the difference between equality comparison and assignment operator ?
  15. What is an if statement ?
  16. What is an else and elif statement ?
  17. What is Boolean data type ?
  18. What is an or operator ? How does it works ?
  19. What is max() and min() ?
  20. What are loops ? What is a while loop ?
  21. What is an infinite loop ?
  22. How to find factorial for a given positive integer using python ?
  23. What is a break statement ?
  24. What is multiple assignment ?
  25. What is a not statement ?
  26. How to find range of a set using python ?
  27. What are some good programming conventions ?

From today onward , I will begin my journey into learning more new concepts from Lesson 10 and onward. With this section I have completed about 30% of the course.

Lesson 1-4: Intro to Computer science program (Udacity)

One often meets his destiny , in the path he takes to avoid it

-Master Oogway

So , by completing lesson 1-4 from “Intro to CS” course of Udacity , I have learned soo much and I have also completed unit 1 of this course. Here are the links for for code of each lesson (except for lesson 4) –
Lesson 1 :
Lesson 2 :
Lesson 3 :

So , these are some of the topics I have learned are :

  1. What are web-crawlers ?
  2. Application-specific devices (e.g. Toaster) & Universal machines (e.g. Computers)
  3. What is a program ?
  4. What is a python interpreter ?
  5. Natural languages v/s programming languages
  6. What is a syntax error ?
  7. What is Backus-Naur form (BNF) ? & What are it’s rules ?
  8. Basic rule for python grammar for arithmetic & expressions
  9. What is a nanostick ?
  10. What is a compiler ?
  11. What is a variable ?
  12. What is a string ?
  13. What is a string index ? and How to use string index to extract characters out of strings ?
  14. How to select string subsequence ?
  15. What is find() ? & How to use find() with substring as parameter ?
  16. How to use find() with a number being the 2nd parameter for function ?
  17. How to extract the 1st hyperlink from a webpage stored in form of a string ?
  18. swapping of variables : a,x=x,a
  19. What is str() ? and how to use it ?
  20. What is len() ? and how to use it ?
  21. What is int() ? and how to use it ?
  22. How to create a palindrome checker ?
  23. How to build a text replacement program ?
  24. What is indentation & white-space ? and why are they helpful ?

Learning soo many concepts in a couple of days was actually a delightful journey for me. I have already Unit 2 (lesson 5-9) which will be primarily about control structures and procedures in python.