about | help | code help+videos | done | prefs |
Given a Stack of integers and a target value, if the target value exists somewhere in the stack, push the target value's 1-based index onto the top of the stack and return the stack. The 1-based index means that if the target value is on the top of the stack already, push a 1. If it is the second element in the stack, then push a 2. If the target value does not exist in the stack, push a -1 to the top of the stack. YOUR FIRST TWO LINES OF CODE MUST BE: Stack<Integer> stack = new Stack<Integer>(); stack.addAll(list); stack_searchAndPushIndex([1, 2, 3, 4, 5], 3) → [1, 2, 3, 4, 5, 3] stack_searchAndPushIndex([1, 2, 3, 4, 5], 6) → [1, 2, 3, 4, 5, -1] stack_searchAndPushIndex([1, 2, 3, 4, 5], 1) → [1, 2, 3, 4, 5, 5] ...Save, Compile, Run (ctrl-enter) |
Progress graphs:
Your progress graph for this problem
Random user progress graph for this problem
Random Epic Progress Graph
Copyright Nick Parlante 2017 - privacy