There is an algorithms tournament taking place where teams of programmers compete against each other to solve problems as fast as possible. Teams compete in a round robin, where each team faces off against all other teams.

Only two teams compete against each other as a time, for each competition, one team is designated the home team while the other is the away team.

In each competition there’s always one winner and one loser, there are no ties.

A team receives 3 points if it wins and 0 points if it loses. …

I recently created a solution for the three number sum problem in JavaScript, and now that I want to practice my Python, I thought I’d create a similar solution in Python. Let’s begin.

Create a function that takes an array and a target integer that represents the sum. The function should find all triplets in the array that sum up to the target integer.

The numbers should be in ascending order.

If on three numbers sum up to the target integer, then the function should return an empty array.

First, we’ll be sorting the array and create a variable to…

Given two input strings, (a) and (b), return (true) if two letters in (a) can be swapped so that the result is equal to (b), otherwise return (false).

Note: swapping letters is defined as taking two indices (i) and (j), where (i) is not equal to (j), and swapping the elements at those indices.

Here’s an example:

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]

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…

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.

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.

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.

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.

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.

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.

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 way I think about approaching this…

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.

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