We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
@rahulrajpl
How is the runtime complexity O(n)?
p.index(i) will alone take O(n), but in your solution p.index(i) is inside another p.index() which makes the runtime complexity to be O(n2). Further, (p.index(p.index(i)+1)+1) ie., O(n2) statement executes max(p) or n times which makes the overall complexity O(n3)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sequence Equation
You are viewing a single comment's thread. Return to all comments →
@rahulrajpl How is the runtime complexity O(n)? p.index(i) will alone take O(n), but in your solution p.index(i) is inside another p.index() which makes the runtime complexity to be O(n2). Further, (p.index(p.index(i)+1)+1) ie., O(n2) statement executes max(p) or n times which makes the overall complexity O(n3)