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 !




