Advertisement
Guest User

Untitled

a guest
Jul 27th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. Problem 1 – Sequences
  2. You are given an integer array arr, consisting of N integers. Find the number of non-decreasing consecutive subsequences in arr. Every sequence starts after the previous one. For example: if the array arr consists of the numbers 1, 2, -3, 4, 4, 0, 1, the number of non-decreasing consecutive subsequences is 3 (the first is 1, 2, the second is -3, 4, 4 and the third is 0, 1)
  3. Your task is to write a JavaScript method named “Solve” that solves the problem.
  4. Input
  5. The method Solve accepts a zero-based array of strings. Each of the string represents an integer. Element 0 of the array is the number N. Next N elements (from 1 to N) construct the array arr.
  6. Output
  7. Your method should return a single number - the number of non-decreasing consecutive subsequences.
  8. Example code
  9. function Solve(params) {
  10. var N = parseInt(params[0]);
  11. var answer = 0;
  12. // Your code here...
  13. return answer;
  14. }
  15. Constraints
  16. • N will be between 1 and 10 000.
  17. • Each element of arr will be between -2 000 000 000 and +2 000 000 000.
  18. • Allowed working time for your program: 0.1 seconds. Allowed memory: 16 MB.
  19. Examples (each line represents an element from the only argument of Solve)
  20.  
  21. Example input: Example output:
  22. 7 3
  23. 1
  24. 2
  25. -3
  26. 4
  27. 4
  28. 0
  29. 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement