## Merge Two Sorted Linked Lists

Problem Statement We have to implement the mergeTwoLists function that takes the head nodes of two sorted linked lists as input and returns the head node of the merged linked list as the output. Optimal Solution To merge both linked lists we can use the two-pointer approach by maintaining an iterator on both linked lists and comparing their values. The smaller value will be selected and inserted at the end of a new list....

January 29, 2024 · 4 min · Avnish

Problem Statement We have to implement the reverseList function that takes the head node of a linked list as an input and returns the head node of the reversed linked list in the output. Brute Force Solution If we iterate over the input linked list and insert its value at the beginning of a new list the result would be a reversed linked list. Psuedo-code for the Brute Force Solution reversedLinkedList = LinkedList() temp = linked_list....

January 26, 2024 · 4 min · Avnish

## Finding Elements in an Array that Sum Up to a Target Value

Problem Statement We have to implement a twoSums() function that takes an integer array and a target value as inputs. It returns the indexes of two elements in the input array which could be summed up to the target value. It is assumed that the input array contains only one valid pair of elements that sum up to the target value. Brute Force Solution The brute-force solution will find the sum of all element pairs in the array using nested loops....

October 15, 2023 · 4 min · Avnish

## Identify Anagrams

Problem Statement We have to implement an isAnagram() function that takes two strings as input and returns true if they both are anagrams and false otherwise. Multiple words could be anagrams of each other if they contain the same characters with the same frequency of occurrence. For word counter: trounce is an anagram. trouncee isn’t an anagram, because the character e appears twice in trouncee. tounce isn’t an anagram, because the character r is missing....

October 12, 2023 · 5 min · Avnish

## Checking an Array for Duplicate Values

Problem Statement We have to implement a function containsDuplicate() that takes an integer array as input and returns true if an element occurs more than once and false otherwise. Brute Force Solution The simplest solution for this problem would be two nested loops, where the first loop will select an element and the second loop will select another element from the array and compare them. On the first occurrence of a duplicate element, the function will exit while returning true....

October 10, 2023 · 3 min · Avnish