Java: Functions, Loops, Variables, and a sock merchant

August Radjoe
3 min readAug 20, 2019

Introduction to the series, Structure of a Java program and stuff

First, I talk about basics, such as in the previous article. In this one, I am going to pick up a problem from HackerRank’s interview prep kit and solve it, explaining Functions, For loops and working with variables.

Over the next few articles, I will focus on all basics such as OOPs, Methods, Constructors, the ten I/O types in Java.

I will dedicate a few articles solely to advanced OOPs.

From there we will move to databases, networking, concurrency and then make a text editor and a breakout game.

All that said and done, let’s jump on to our first problem. But first, music recommendation for this post is a beautiful Synthwave mix I stumbled upon late one night in Mumbai.

Back to the problem:

Attached the image because the markdown from HackerRank wasn’t getting copied

Fairly simple problem, let me break it down.

A large pile of socks where each sock is represented by an integer stored in an array. Said Socks would have the same integer value if they are the same color. Find out the number of pairs of socks.

Fine, sounds like a good problem to me (Personal lifehack: Tie a pair of socks together so they don’t get mixed up.)

--

--

August Radjoe

Now: MS CS @ Boston U / Prev: Ignite Tournaments, DeFi Alliance, Persistence, Eth India Co