# Category: Intermediate

## Find consecutive segments in an sorted array

Problem : Number list compressing. Given an sorted array. Input: sorted number list [ 1, 2, 3,10, 25, 26, 30, 31, 32, 33] Output: find consecutive segments print: 1-3, 10, 25-26, 30-33 Logic :...

## Rearrange characters in a string so that no character repeats consecutively.

Below are some of the test strings with their expected output. Input: aaabc Output: abaca Input: aa Output: No valid output Input: aaaabc Output: No valid output Logic : Create frequency map of the...

## Create a minimal height binary search tree from given sorted array of unique integers

Problem description : Given a sorted (increasing order) array with unique integer elements, create a binary search tree (BST) with minimal height. Input : A sorted array with unique integer elements // [0, 1,...

## Determine if a binary tree is balanced

A balanced tree is defined to be a tree such that the heights of the two subtrees of any node never differ more than one. Input : The root of a binary tree Output...

## Given a singly linked list find if it is palindrome

Problem description : Write a function to determine if a singly linked list is a palindrome. Input : A linked list Output : Boolean (true or false) Approach 1: Reverse and compare the linked...

## Partition a linked list around a value

Problem description : Write code to partition a linked list around a value val, such that all nodes less than val come before all nodes greater than or equal to val. Input : A...

## Find all the prime factors for the given number

Input : A number // 10 Output : An array // [2, 5] Logic : Key here is that we need to check the divisor starting with 2 to the square root of the...

## Transform json to json

Problem description : Write a function which transforms the given JSON as shown belows : Input : Given an endorsment array with objects containing skill and user keys var endorsements = [ { skill:...

## Filter and sort the given array

Problem description : Write a function that filters the invalid entries from the given array by removing the following elements : which does not have either id or extension property whose id value is...

## Random Dice Roll Challenge

Problem description : Write a javascript function that accepts a string argument in the format {digit}d{digit}; where The first digit represents the number of dices. The second digit represents the number of sides. The...