Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 6420 |

@blackshadows | 6380 |

@mb1973 | 5704 |

@Quandray | 5245 |

@akhayrutdinov | 5111 |

@saiujwal13083 | 5046 |

@sanjay05 | 3762 |

@kirtidee18 | 3673 |

@marius_valentin_dragoi | 3523 |

@mantu_singh | 3510 |

@sushant_a | 3459 |

Complete Leaderboard | |

Handle | Score |

@cfwong8 | 1156 |

@gurshehzadsingh | 676 |

@nithinreddy3210 | 642 |

@jha8768 | 577 |

@Run_for_life | 574 |

@divyagupta221100 | 557 |

@AkashLahoty | 553 |

@aayushdesai01 | 526 |

@riyakumaribkj | 526 |

@2017akku | 521 |

@amansinha74458 | 503 |

Complete Leaderboard |

Given an array **A[] **of size **N** and a positive integer **K**, find the first negative integer for each and every window(contiguous subarray) of size **K**.

**Example 1:**

**Input :
**N = 5
A[] = {-8, 2, 3, -6, 10}
K = 2
**Output : **
-8 0 -6 -6
**Explanation :**
First negative integer for each window of size k
**{-8, 2}** = -8
**{2, 3}** = 0 (does not contain a negative integer)
**{3, -6}** = -6
**{-6, 10}** = -6

**Input : **
N = 8
A[] = {12, -1, -7, 8, -15, 30, 16, 28}
K = 3
**Output :**
-1 -1 -7 -15 -15 0

**Your Task: **

You don't need to read input or print anything. Your task is to complete the function **printFirstNegativeInteger()** which takes the array **A[]**, its size **N **and an integer **K **as inputs and returns the first negative number in every window of size K starting from the first till the end. If a window does not contain a negative integer , then return 0 for that window.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(K)

**Constraints:**

1 <= N <= 10^{5}

1 <= A[i] <= 10^{5}

1 <= K <= N

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

First negative integer in every window of size k

...