Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nonDecreasingSubsequence(inputArray) {
- let result = [];
- let currentBiggestElement = 0;
- for (let i = 0; i < inputArray.length; i++) {
- if (inputArray[i] >= currentBiggestElement) {
- currentBiggestElement = inputArray[i];
- result.push(inputArray[i]);
- } else {
- continue;
- }
- }
- console.log(result.join(' ').trim());
- }
- // For testing:
- // nonDecreasingSubsequence([1, 3, 8, 4, 10, 12, 3, 2, 24]);
- // nonDecreasingSubsequence([1, 2, 3, 4]);
- // nonDecreasingSubsequence([20, 3, 2, 15, 6, 1]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement