Find First Negative Number in Every subarray of Size k using Sliding Window Algorithm in c#

Arkaprava Sinha
Mar 17, 2021

Problem : Find First negative number in every subarray of size k

Explanantion:

Lets say we have an array like this { 12, -1, -7, 8, -15, 30, 16, 18 }

Sub Arrays of size k(k=3) will be below,

{12,-1,-7} {-1,-7,8} {-7,8,-15} {8,-15,30} {-15,30,16} {30,16,18}

First Negative of each sub arrays will be -1,-1,-7,-15,-15,0(as there are no negative numbers)

Code:

--

--

Arkaprava Sinha

Senior Software Engineer@Walmart , Cloud, IoT and DevOps Enthusiast