Skip to main content

3 posts tagged with "day-1"

View All Tags

· 5 min read
Trayi Murti

Let's increase problem level further.

Problem

Given a grid of integers L = [[A1,1, A1,2, A1,3, ..., A1,M], [A2,1, A2,1, A2,3, ..., A2,M], [A3,1, A3,2, A3,3, ..., A3,M], [..., ..., ..., ..., ...], [AN,1, AN,2, AN,3, ..., AN,M]]. Where Ai,j ≥ 0, 0 ≤ i ≤ N, 0 ≤ j ≤ M. You have to find the least perimeter of rectangle which adds up to a given integer K.

· 4 min read
Trayi Murti

So, What if the numbers can also be negative?

We can't use sliding window algorithm then. First we will compute prefix sum and then sort it with their respective index (sort them as {prefixL[i],i}). Then we will apply binary search on it for every index i to look for an element whose index j is greater than index i and whose value is equal to prefixL[i] + K. This will take O(nlog(n))\cal{O}(n \cdot \log(n)) time.

· 3 min read
Trayi Murti

Let us start with a problem

Problem

Given a list of integers L = [A1, A2, A3, …, AN]. Where Ai ≥ 0, 0 ≤ i ≤ N. You have to find the shortest contiguous segment in the list which adds up to a given integer K. If there are more than one such segment, print one of them.