Data Structures

Algorithms: Adjacent Element Products

Hi there :), our question for today is from code signal, and it’s an easy problem. Given an array of integers, find the pair of adjacent elements that has the largest product and return that product. Example For inputArray = [3, 6, -2, -5, 7, 3], the output should be adjacentElementsProduct(inputArray) = 21. 7 and 3 produce the largest …

Algorithms: Adjacent Element Products Read More »

Leetcode – Robot Return To Origin Problem: Solution in Javascript and PHP

Robot Return To Origin Problem: Solution in Javascript and PHP

  Question There is a robot starting at position (0, 0), the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves. The move sequence is represented by a string, and the character moves[i] represents its ith move. Valid moves are R …

Robot Return To Origin Problem: Solution in Javascript and PHP Read More »

The Longest Common Prefix Amongst An Array of Strings – Implementation in Javascript and PHP

Today, we’ll take a look at another easy problem on leetcode, finding the longest common prefix string amongst an array of strings. Question Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Example 1: Input: [“flower”,”flow”,”flight”] Output: “fl” Example …

The Longest Common Prefix Amongst An Array of Strings – Implementation in Javascript and PHP Read More »

Two Approaches to Solving The TwoSum Problem – Easy Javascript Implementation

If you’ve been practicing some data structures and algorithms, then you have probably come across the TwoSum problem. It’s a popular and easy question to help you get started. The problem can be asked in multiple ways. We’ll go for the generic question as seen on leetcode. Question Given an array of integers, return indices of …

Two Approaches to Solving The TwoSum Problem – Easy Javascript Implementation Read More »

A Singly Linked List Implementation In Javascript

Once you start exploring data structures outside of arrays, you’ll probably if not certainly bump into lists first. A list is an abstract data type (a type for objects whose behaviour is defined by a set of value and a set of operations) that represents a countable number of ordered values, where the same value …

A Singly Linked List Implementation In Javascript Read More »