Google Interview Question

Правка en1, от humane_rdgfc, 2025-10-25 16:34:17

Given an array { 1, 7, 7, 2,3, 7, 6,-20}. Find the longest nondecreasing contiguous sequence with substitution. we can substitute any array element with any integer such as all occurrences of 7 replaced with 1. In this way new array would be { 1,1,1,2,3,1,6,-20}. here, the answer would be 5 from [1,1,1,2,3] Only one substitution is allowed.

Could anyone help me in solving this question. currently i have only bruteforce one O(n*k^2),k is no of unique elements.If anyone has better solution than this please comment below.Expected TC is O(n) ish.

Thanks in advance !

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский humane_rdgfc 2025-10-25 16:34:17 599 Initial revision (published)