The Prompt

Create a function that takes an array of at least three integers and returns a sorted array of the three largest integers in the input array.

Note: You cannot sort the input array

The function should return duplicate integers, if necessary. For example:

Input array -> [10, 5, 9, 10, 13]

Output -> [10, 10, 13]

The Code

So we’re given the prompt and the starting code below:

First, we can create a variable to represent the final output array. At this point, the code can’t derive which elements within the input array are the largest, so we’ll initiate our variable with…


The Prompt

Create a function that takes an array of positive integers and returns the maximum sum of the non-adjacent elements in the array.

If the input array happens to be empty, return a 0.

The Code

First, let’s create a template for the function.

Now, to handle an edge case provided by the prompt, if the input array is empty, then the function must return 0. This can be handled with a simple (if) statement.


The Prompt

Create a function that takes in a Binary Tree and inverts it. The function should swap every left node in the tree for its corresponding right node.

Note:

  • Each Binary Tree node has an integer value, a left child node, and a right child node.
  • The children nodes can either be BinaryTree nodes themselves or None/null.

The Code


I recently came across a problem that asked to create a function that will check whether or not an array is monotonic.

At first glance…. I had no idea what a monotonic array was so here’s a simple explanation.

A monotonic array is an array that has elements in a completely non-increasing or non-decreasing manner. But wait…. what does that mean?

Non-increasing elements aren’t exclusively decreasing, simply put, they just don’t increase (but you can have elements repeat, consecutively, technically the elements are not increasing if it repeats itself).

And likewise, Non-decreasing elements aren’t exclusively increasing, they just don’t decrease…


Today, we’ll be going over a simple array problem from Leetcode. Problem number 977, which asks to return an array with the squares of each element. Let’s start.

The Prompt

Given an integer array, sorted in non-decreasing order (I don’t know why they can’t just say “ascending” order… honestly I thought it was hilarious), and return an array of the squares of each number sorted in non-decreasing order.

Conceptual Overview

Thinking about the problem at first glance, a brute force solution would be so simply traverse through the input array, square each element, and then return the final modified array. …


As I’m studying for technical interviews, I came across a problem that was asking me to move specific elements to the ending of an input array. Since it’s a medium level problem , I thought I’d create a blog post about how I approached the problem. Let’s start.

The Prompt

Given an array of integers and an integer, create a function that moves all the instances of the given integer to the end of the array. Then, return the modified array.

  • **Note: The order of the integers within the array doesn’t need to be maintained.

The Approach

The way I think about approaching this…


The Prompt

Create a function that takes a non-empty array of distinct integers and an integer representing a target sum.

The function should find all the quadruplets in the array, of which the sum is equal to the target sum.

Return a two-dimensional array of all these quadruplets in no particular order.

If there are no quadruplets that add up to the target sum, return an empty array.

The Approach

Starting off, we have to think about how to track the combinations of the elements in the input array. …


This is a problem that asks us to create a function that will check to see if a sequence of numbers is a subsequence of a given array.

A subsequence of an array is a set of integers that don’t have to be adjacent in the given array but are in the same order as they appear in the array.

For example, given an array [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], a valid subsequence would be [2,4,6,8,10]. …


As I’m studying on HackerRank I came across the diagonal difference challenge. I’m definitely guilty of over-thinking and creating ways that resulted in wasted time.

After many tries, I eventually solved the challenge and I’m writing this article to simply explain it as a reference to myself and other developers. Let’s get started.

The Prompt

Given a square matrix, calculate the absolute value of the difference between the sums of its diagonals.

An example matrix is below:


As a software engineer, I practice frontend development by designing and creating projects that look similar to popular modern applications. When I first learned JavaScript and React, I created class components with state being in an object. The more I used React, I found myself creating functional components and using hooks to reuse state between components.

Traditionally, React doesn’t provide a method to create and implement “reusable behavior” to a component. According to React’s documentation, there are patterns like <render props> and <higher-order components> that attempt to solve this issue. …

Karan S. Chauhan

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