0 0 votes you are given an array which contain both positive and negative integers in it and asked to design an algorithm to find maximum sum which doest contain twp consecutive numbers .what is the time complexiy of efficient algorithm ? nlogn n2 n n2logn Algorithms algorithms algorithm-design time-complexity + – akankshadewangan24 1.6k views answer comment Share Follow Print See all 9 Comments 9 9 Comments reply Show 6 previous comments Rishabh Gupta 2 commented Dec 2, 2017 reply Follow flag I think the best we can do is in nlogn. First, sort it, and then traverse only the positive numbers(just ignore the duplicates while traversing). Other two options are greater than this, so not to consider them. Don't know whether it can be done in n or not. 0 0 replyShare srivivek95 commented Dec 2, 2017 reply Follow flag @ Rishabh Gupta 2 After sorting how will you preserve the condition that numbers are not consecutive? 0 0 replyShare Anu007 commented Dec 2, 2017 reply Follow flag Find max element of array. Find 2nd max element of array each time by check no adjacent element taken . by this way we get O(n2) 0 0 replyShare Please log in or register to add a comment.
0 0 votes I think in this question apply 2 pass bubble sort which give two largest number which is order of (n) and add two last elements which give constant avadh answered Jun 30, 2018 avadh comment Share Follow 0 reply Please log in or register to add a comment.