Time planner

Implement a meeting planner that can schedule meetings between two persons at a time.

Planner input:

dur - Meeting duration in seconds (a positive integer).

timesA, timesB - Availability of each person, represented by an array of arrays.

Each sub-array is a time span holding the start (first element) and end (second element) times.

You may assume that time spans are disjointed.

Planner output:

Array of two items - start and end times of the planned meeting, representing the earliest opportunity for the two persons to meet for a dur length meeting. If no possible meeting can be scheduled, return an empty array instead.

Design and implement an efficient solution and analyze its runtime and space complexity.

example:

timePlanner(60, [[150, 300], [100, 200]], [[50, 400], [200, 300]]);
// [100, 160]

Read More

Share Comments

Matrix piral print

Given a 2D array (matrix) named M, print all items of M in a spiral order, clockwise.

For example: [

[1, 2, 3, 4, 5],

[6, 7, 8, 9, 10],

[11, 12, 13, 14, 15],

[16, 17, 18, 19, 20]

]

1 2 3 4 5

6 7 8 9 10

11 12 13 14 15

16 17 18 19 20

example:

const arr = [
[1, 2, 3, 4, 5],
[6, 7, 8, 9, 10],
[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20]
];
matrixSpiralPrint(arr);
// 1 2 3 4 5 10 15 20 19 18 17 16 11 6 7 8 9 14 13 12

Read More

Share Comments

Array of array products

Given an array of integers ‘arr’, write a function that returns another array at the same length where the value at each index i is the product of all array values except ‘arr[i]’.

Solve without using division and analyze the runtime and space complexity

Example:

arrayOfArrayProducts([2, 7, 3, 4]);
// [7*3*4, 2*3*4, 2*7*4, 2*7*3]

Read More

Share Comments

Word count engine

Implement a document scanning engine that receives a text document doc and returns a list of all unique words in it and their number of occurrences, sorted by the number of occurrences in descending order.

The engine should ignore punctuation and white-spaces.

example:

wordCountEngine('practice makes perfect. get perfect by practice. just practice!');
// [[practice, 3], [perfect, 2], [make, 1], [get, 1], [by, 1], [just, 1]]

Read More

Share Comments

Rotated sorted array

searching an element in a rotated sorted array(ascending order) and return the index of it or -1

example:

rotatedSortedArr([3, 0, 1, 2], 1);
// 2

Read More

Share Comments

A task to handle URI

Write a function, checkURIs(uri1, uri2) that can check if 2 URIs are equivalent. The function should return true if match, and false otherwise


Constraints and assumptions are as follow:

A port that is empty, or not given, is equivalent to the default port of 80

Comparisons of scheme names must be case-insensitive

Comparisons of host names must case-insensitive

Comparisons of path, hash, and querystring must be case-sensitive

Paths may contain traversal tokens . (same dir) and .. (one dir up) which must be accounted for

Characters are equivalent to their % HEX HEX encodings. (Other than typical reserved characters in urls like , / ? : @ & = + $ #)

Query string parameters must be equivalent in arbitrary order, BUT query string arguments of the same name must be listed in the same order in both URIs to be equivalent. There may be multiple (not just 2) args of the same name that need to be accounted for.

In-URI basic auth may be present: e.g. http://uname:passwd@host.com/foo/bar.html, auth must be case-sensitive


example:

checkURIs('http://abc.com:80/~smith/home.html',
'http://ABC.com/%7Esmith/home.html'); // true
checkURIs('http://abc.com/drill/down/foo.html',
'http://abc.com/drill/further/../down/./foo.html'); // true
checkURIs('http://abc.com/foo.html?a=1&b=2',
'http://abc.com/foo.html?b=2&a=1'); // true
checkURIs('http://abc.com/foo.html?a=1&b=2&a=3',
'http://abc.com/foo.html?a=3&a=1&b=2'); // false

Read More

Share Comments

String compression

Write a function compress(str), which shortens strings by reducing consecutive character repetitions.

Note: input string will only contain [a-z]+

example:

compress('aaaabbaaaababbbcccccccccccc');
// a4b2a4b1a1b3c12

Read More

Share Comments

The smallest palindrome

Find the smallest palindrome in a given string

A palindrome is a word or a phrase that is the same whether you read it backwards or forwards, for example the word `refer’.

example:

getSmallestPalindrome('the nurses run');
// nurses run

Read More

Share Comments

Quad combination

Given an array of numbers arr and a number S, find 4 different numbers in arr that sum up to S.

Write a function that gets arr and S and returns an array with 4 indices of such numbers in arr, or null if no such combination exists. Explain and code the most efficient solution possible, and analyze its runtime and space complexity.

example:

findArrayQuadCombination([1, 2, 3, 4, 5, 6, 7, 8], 12);
// [0, 1, 2, 5]

Read More

Share Comments

Smallest substring of all characters

Given an array with unique characters ‘arr’ and a string ‘str’, find the smallest substring of ‘str’ containing all characters of ‘arr’.

example:

getShortestUniqueSubstring(['x', 'y', 'z'], 'xyyzyzyx');
// zyx
getShortestUniqueSubstring(['x', 'y', 'z'], 'xyyzyzy');
// xyyz

Read More

Share Comments