Minimum Size Subarray Sum

Minimum Size Subarray Sum (Smallest subarray whose sum is greater than or equal to target).

Given an array of positive integers and a positive number k. Find the smallest contiguous subarray whose sum is either greater than or equal to k. If no subarray is found then return 0.

For example –

Example 1 –

  Input :  {7, 2, 1, 1, 6, 5},  k = 11

Output:  2 ( subarray {6, 5} has the minimum length )

Example 2 –

  Input : {1, 4, 3},   k = 12

Output: 0 (No subarray is possible)

Merge Overlapping Intervals

In this post, we are going to solve a problem merge overlapping intervals.

Given a list of time intervals. Each interval has a start and end time. Write a code to merge all overlapping intervals. The given intervals may or may not be sorted.

For example –

Example 1-

Input: [[1,4], [2,5], [6,9]] Output: [[1,5], [6,9]]

Example 2-

Input: [[7,8], [2,3], [5,9]] Output: [[2,3], [5,9]]

Example 3-

Input: [[1,4], [2,6], [3,5]] Output: [[1,6]]

Remove Nth Node from the End of a Linked List

Given a singly linked list, write a code to remove nth node from the end of a linked list. In this problem, you can assume the value of n is always valid.

For example –

In this example, the input linked list has four nodes and we have to remove 2nd node from the end.

Input –

15 -> 9 -> 8 -> 5 -> NULL , N = 2

After removing second node (node whose value is 8) from the end, the output is

15 -> 9 -> 5 -> NULL