Cracking the Coding Interview With LeetCode — Day 1

To crack the big technology company’s interview code LeetCode Is a well-known website to practice various code questions. In this series, we’ll use two languages, Python and Go, to address particular questions about data structures and algorithms and understand some essential theories.

Photo by Christina Morillo from Pexels

Hi, I am Mahmud. I am doing a course where the objective is to learn DSA and solve questions from LeetCode. The course instructor is Shajal Ahamed, a Backend Engineer and DevOps who worked in Air Asia.

his course will cover many topics on DAS, like Stack, Queue, Binary Tree, Heap, Graph, Bit Manipulation, 2D array, String, Greedy, Binary Search, Linked List, Dynamic Programming, Recursion. Also, we will solve more than 120 problems from LeetCode. I will document all the instructions and notes in this series of articles to help others learn about this journey, and anyone can follow to prepare for the giant tech company. It will also be helpful for me in the future to revise the instructions. So let’s started.

All the Notes and Instructions

Here, I will mention all the instructions our instructor told us to follow and the topics we learned.

Instructions 1: We should practice coding on white paper or hand. Because most companies want to see how we approach the problems with logic. Companies like, Google Facebook could tell you to write code on word files or blank filed to code. Maybe you miss some syntactical mistakes, but that’s enough if you show your logic.

Notes 1: We will use python and Go; these two languages used different mechanisms to run on our machine. Python is an interpreter-based language and Go a compiler-based language. Let’s know the difference,

We generally write a computer program using a high-level language that humans understand, called source code. On the other hand, a computer only understands the program written in 0’s and 1’s in binary, called the machine code.

Collected from Guru99.com

Compiler and interpreter both convert High-level language to machine code. A compiler will convert the code into machine code (create an exe) before the program runs, and interpreters convert code into machine code when the program is run. To learn more about the difference, visit guru.

Instructions 2: It is preferable to learn in a group rather than alone. It encourages us in continuing to learn and comprehend.

To do so, we created a Discord group where we can share our learning process, challenges, and various things.

Instructions 3: We should start using Linux. It will help us to be better developers in the future.

Currently, Zorin OS is one of the most trending Linux distros. Soon, I will start using it. You can also try this one.

Notes 2: Let’s write some code. First, we will write code on python,

# First Code on Pythonprint("Hello Python programmer.")# To run on terminal write: python filename.py

On Vs-code with output:

hello.py

So, you can see it’s straightforward on python.

Notes 3: Now, Let’s code on Go,

// First Code on Gopackage mainimport "fmt"func main() {fmt.Println("Hello, Go Developer !!")}

To run on the terminal,

  1. go build filename.go — This will create a .exe file in the location, or you can say machine code file.
  2. Typing ls will show us the file list on the current directory.
  3. ./hello — This command will run the binary file and show us the output.

I know it’s pretty much different than python.

Example Explanation(From w3school)

Line 1: In Go, every program is part of a package. We define this using the package keyword. In this example, the program belongs to the main package.

Line 2: import (“fmt”) lets us import files included in the fmt package.

Line 3: A blank line. Go ignores white space. Having white areas in the code makes it more readable.

Line 4: func main() {} is a function. Any code inside its curly brackets {} will be executed. Also, this main function is an entry point where the computer will start its execution.

Line 5: fmt.Println() is a function made available from the fmt package. It is used to output/print text. In our example, it will output “Hello World!”.

Two language difference

These are the two different codes to print just a line. In the output, you can see the go file execution.

In both code examples, we can see that we show a string line. So, let's know what string is?

Notes 4: String- It comprises a series of characters that may include spaces and numerals. The words “Burger” and “I ate 3 burgers,” for example, are both strings. If provided correctly, even “12345” may be deemed a string. To be identified as a string rather than a number or variable name, programmers usually encapsulate strings in quotation marks.

Notes 5: An exciting fact we should note know that Go is not an OOP language. So, we will not call the method to any function.

Notes 6: Every programming language their have some keyword. These keys are reserved for a specific purpose. We should know about those key worlds. Here is a link for python keywords and Go keywords.

Notes 7: Now, we will see the same code using the function. In both languages,

Example of Function in both languages

Instructions 4: To learn more about Go, GoByExample will be a good choice.

Notes 8: Now, we will learn the loop by doing code in both languages.

Here, one important thing we have to learn is how to assign value.

In Go code, you can see we assign zero, like i:=0

So, What does it means,

Example:

a:=5. Means, var a int = 5.

Var = key

A = variable name

int = integer data type

5 = assigned value.

Also, a:= 5. Here Go detect automatically understands that it’s an integer type value.

Notes 9: Let’s understand how these loop functions worked. Basically repetitive work done by the loop. It has a starting step and end step, also, a counting step that tells to go forward or backward.

Loop

Notes 10: Difference between For loop and while loop. Though, Go doesn’t have a while loop.

For loop first, start its initial step, then check condition, increment and at then end execute its internal work.

Whereas, before stating the while looping it initializes its starting and then checks the condition and does its internal work than at last end with increment.

Instructions 5: Home Work is to learn the Go language basics from GoByExample, up to Structs.

These are all the notes and instructions for the first-day class. I know It’s just the basic discussion, but it’s important to know all these things. One thing we have to know is that to learn a new skill we have to give time and practice a lot. Hopefully, we will learn more topics and solve questions from Leetcode.

Comment your valuable suggestions and if found any mistakes. With your support, I will write more content on different topics.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
B M ASHIK MAHMUD

Hi, I am Mahmud. I love to share my ideas and learning strategies. You know, Sharing is caring. To know me more, check out my all links, bio.info/imash