is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.
CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.
Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.
Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.
Coudn't edit my previous reply. Hence, adding it as a new post:
Made edits to the code, to remove redundancy
Assumption: the question has a typo in the explanation:
Should be " [a1, a2, a3, ..., ak] where a1 > a2, a2 < a3, a3 > a4, ..." for the graph to look like \/\/\/
Algorithm:
Keep track of a boolean: isLesser. the boolean is relative to current element in consideration
if the sequence is alternating:
a1> a2 => isLesser = false
a2 < a3 => isLesser = true
a3 > a4 => isLesser = false
and so on
Hence for the current pair to be counted in the alternating subsequence, the previous value of isLesser should be the inverse of what the current isLesser is expected to be. If so increment the the length of the subsequence, else
count the length of the currentSubSequence length into the max
Time Complexity: O(n)
Space Complexity: O(1)
Coded in Java:
- burnYourBrain March 20, 2016