# JavaScript: Inserting a Node at the Tail of a Linked List

## The Solution to a Problem Picked From HackerRank

In the previous article, we explained how to insert a node at the head of a linked list, and in this one, we will use a challenge from HackerRank to learn how to insert a node at the tail of a singly linked list:

You are given the pointer to the head node of a linked list and an integer to add to the list. Create a new node with the given integer. Insert this node at the tail of the linked list and return the head node of the linked list formed after inserting this new node. …

# JavaScript: Inserting a Node at the Head of a Linked List

## Explained Solution to a HackerRank Problem

For today’s algorithm, we will insert a node at the head of a singly linked list. Here is the challenge that I picked from HackerRank:

Given a pointer to the head of a linked list, insert a new node before the head. The next value in the new node should point to head and the data value should be replaced with a given value. Return a reference to the new head of the list. The head pointer given may be null meaning that the initial list is empty.

The problem is straightforward, let’s move to the solution:

1. Initialize a node…

## A Common Interview Question Asked at Many Companies

This week, we will cover another popular technical interview question from LeetCode’s Top Interview Questions List; Reverse Linked List:

`Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULL`

This article will not give many details about linked lists, but here is a very quick refresher: Linked lists are data structures that represent a series of nodes where each node contains two pieces of information: the value of the node and a pointer/reference to the next node in the list. …

# JavaScript: Capitalizing the First Letter of Each Word in a Sentence

## Explained Solution to a Popular Interview Question

Last week, I was asked to solve one of the most common questions on a technical interview for a software engineer role and I wanted to share my solution with you in today’s article. The challenge was asking to write a program that capitalizes the first letter of every word in a given sentence. Here are a couple of examples:

`Example 1:Input: Hi everyoneOutput: Hi EveryoneExample 2:Input: hello classOutput: Hello Class`

There are several possible solutions to this problem such as using a for loop, `.map()` method, or `.replace()`

# JavaScript: Binary Search Algorithm

## Explained With a Problem From LeetCode

For today’s algorithm, I picked the binary search which is one of the most commonly asked topics in technical interviews. The problem named binary search from LeetCode will be used to explain this concept:

Given a sorted (in ascending order) integer array `nums` of `n` elements and a `target` value, write a function to search `target` in `nums`. If `target` exists, then return its index, otherwise return `-1`.

`Example 1:Input: nums = [-1,0,3,5,9,12], target = 9Output: 4Explanation: 9 exists in nums and its index is 4`

While linear searching checks every single element one at a time…

# JavaScript: Remove Duplicates From Sorted Array in Place

## Challenge Picked From LeetCode’s Top Interview Questions List

Today, we will work on Remove Duplicates from Sorted Array algorithm from LeetCode’s Top Interview Questions List:

Given a sorted array nums, remove the duplicates in-place such that each element appears only once and returns the new length.

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

`Example 1:Given nums = [1,1,2],Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively.It doesn't matter what you leave beyond the returned length.Example 2:Given nums =…`

# JavaScript: Valid Anagram Challenge

## Top Interview Questions List — LeetCode

In today’s blog post, I will build an algorithm that validates given inputs as anagrams. Here is one of the most classic interview challenge named Valid Anagram which I picked from LeetCode’s Top Interview Questions List:

Given two strings s and t, write a function to determine if t is an anagram of s (You may assume the string contains only lowercase alphabets).

Words that are anagrams are formed from another by rearranging its letters, so they will have the same letters with the same frequency in a different order. “listen” and “silent” can be given as an example to…

# JavaScript: How to Solve The Sock Merchant Problem

## A Challenge from HackerRank’s Interview Preparation Kit

For this week’s algorithm, I picked a problem named Sock Merchant from HackerRank. I slightly adjusted the challenge as we will not be using a second parameter for the number of socks:

Given an array of integers representing the color of each sock, determine how many pairs of socks with matching colors there are.

The problem states that we are given an array of integers, where each number represents a distinct color of socks. We will need to write a function that returns the total number of matching pairs of socks that exists in the list.

`Example:Input: 10 20…`

# JavaScript: The Two Sum Problem

## From LeetCode’s Top Interview Questions List

This week’s algorithm; Two Sum, is picked from LeetCode’s Top Interview Questions list:

Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. You may assume that each input would have exactly one solution, and you may not use the same element twice. You can return the answer in any order.

Check this example out to better understand what the problem is asking:

`Example:Input: nums = [2,7,11,15], target = 9Output: [0,1]Output: Because nums + nums == 9, we return [0, 1].`

Array type of…

# JavaScript: Use a Recursive Function to Determine If a Given Number is Even

## Explained the Solution of an Exercise in Eloquent JavaScript

`Example 1:Input: (5)Output: falseExample 2:Input: (82)Output: trueExample 3:Input: (-1)Output: false`
In this exercise, we will not use the modulo/remainder operator (`%`). …
{"ft_lang_label":"__label__en","ft_lang_prob":0.8510432,"math_prob":0.5869394,"size":5594,"snap":"2021-31-2021-39","text_gpt3_token_len":1283,"char_repetition_ratio":0.11413238,"word_repetition_ratio":0.042797495,"special_character_ratio":0.22667143,"punctuation_ratio":0.119650654,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95408577,"pos_list":[0,1,2],"im_url_duplicate_count":[null,3,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-07-29T14:59:48Z\",\"WARC-Record-ID\":\"<urn:uuid:9478056f-ffe2-415e-a068-3722b0eb91f4>\",\"Content-Length\":\"254183\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7edd561d-b987-40d3-8236-97232d5b3921>\",\"WARC-Concurrent-To\":\"<urn:uuid:758b6098-4cb6-4ea7-86d4-8cf636276050>\",\"WARC-IP-Address\":\"162.159.153.4\",\"WARC-Target-URI\":\"https://bahayg.medium.com/?source=post_internal_links---------3----------------------------\",\"WARC-Payload-Digest\":\"sha1:NC3WK3PZFGBBFOHBICLP57JVOE7D7KGG\",\"WARC-Block-Digest\":\"sha1:I5GGRXNZ4FKBTBXHWMVSIVHOJHMCJLQM\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046153860.57_warc_CC-MAIN-20210729140649-20210729170649-00314.warc.gz\"}"}