brag: A Command Line Tool for Building a Bragging Document

Inspired by Julia Evan’s blog Get your work recognized: write a brag document I created this tool to keep a record of my brags in Markdown Format and refer them later to create a formatted bragging document. A bragging or hype document is created to keep a record of achievements over time. This document/information extracted from this document could be shared with managers or used for self-reflection and improvement. I refer to it during my daily standups and weekly sync-up meetings. ...

March 19, 2024 · 9 min · Avnish
The reorderList function will return the head of the reordered linked list given a linked list as input

Reorder Linked Lists

Problem Statement We have to implement the reorderList function that takes the head node of a linked list as input and reorders its nodes in the format specified below. Given an input list like the following: $$Node_0 \rightarrow Node_1 \rightarrow Node_2 \rightarrow \dots \rightarrow Node_{(n-2)} \rightarrow Node_{(n-1)} \rightarrow Node_n$$ the reorderList function should reorder its nodes as: $$Node_0 \rightarrow Node_n \rightarrow Node_1 \rightarrow Node_{(n-1)} \rightarrow Node_2 \rightarrow Node_{(n-2)} \rightarrow \dots$$ ...

February 15, 2024 · 9 min · Avnish
The mergeTwoLists function will return the head of the merged linked list given two sorted linked lists as input

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. The result would be a merged sorted linked list. ...

January 29, 2024 · 4 min · Avnish
The reverseList function will return the head of the reversed linked list

Reversing Linked Lists

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. ...

January 26, 2024 · 4 min · Avnish
Linked Lists

Linked Lists

The linked list data structure is used to store sequential data using nodes. A node contains a value and the memory address of the next node. Memory for a new node is allocated dynamically i.e. nodes are stored in the next available memory location. Unlike arrays where contiguous blocks of memory are allocated during declaration. The first element in a linked list is marked by its head pointer. Here is an implementation of Linked List in Go ...

November 17, 2023 · 13 min · Avnish
The longestConsecutive function will return the length of the longest sequence if consecutive numbers in the input array

Finding the Longest Consecutive Sequence in an Array

Problem Statement We have to implement the longestConsecutive function that takes an integer array as input and returns the length of the longest sequence of consecutive integers. For example, in array [4, 2, 7, 8, 1, 5, 6, 0] we have two sequences of consecutive integers: [0, 1, 2] and [4, 5, 6, 7, 8]. The longest sequence ([4, 5, 6, 7, 8]) has length 5. ...

November 9, 2023 · 6 min · Avnish
The encode function will encode a list of strings to a single string while the decode function will take the encoded string and return the original list of strings as output

Encoding and Decoding Functions for Strings

Problem Statement We have to implement an encode function that takes a list of string values as input and returns a single encoded string that could be transmitted over a network. On the other side of the network, the decode function will take the encoded string as input and return the original list of string values as output. A delimiter could be used to differentiate between words. For example, ["Hello", "World"] could be encoded with comma delimiter (,) to "Hello,World". ...

November 6, 2023 · 7 min · Avnish
The isValidSudoku function will return true if the input matrix represents a valid sudoku grid and false otherwise

Checking the Validity of a Sudoku Grid

Problem Statement We have to implement an isValidSudoku function that takes a 9x9 matrix (representing a Sudoku grid) as input and returns true if the grid is valid and false otherwise. Sudoku Grid A Sudoku grid is valid if Every row contains digits from 1 to 9 without repetition. Rows in a Sudoku Grid Every column contains digits from 1 to 9 without repetition. ...

November 2, 2023 · 12 min · Avnish
The productExceptSelf function will returns an array of products of all the elements without the element at the same index in input array

Building a Product Array without the Element Itself

Problem Statement We have to implement a productExceptSelf function that takes an integer array nums as input and returns another array answer as output. The element answer[i] will be the product of all elements in inputArray except inputArray[i]. The implementation should not contain a division (/) operation because the answer array could also be created by iterating over all elements in inputArray and dividing them from the product of the complete array. ...

October 28, 2023 · 5 min · Avnish
The topkFrequent function will return the top k most frequent elements in an array

Finding Most Frequent Elements in an Array

Problem Statement We have to implement a topKFrequent function that takes an integer array and a value k as input and returns the k most frequent elements in the input array. For example, topKFrequent({1, 1, 2, 2, 3, 5, 2}, 2) will return the top 2 most frequent elements in the array i.e. {2, 1}. If multiple elements have the same frequency, then any of them could be returned in the solution as long as its length is k. ...

October 26, 2023 · 7 min · Avnish