Category «Lists»

Greater than neighbours

Greater than neighbours. Given a list of numbers, determine and print the number of elements that are greater than both of their neighbors. The first and the last elements of the list should not be considered because they don’t have two neighbors. Test Case Input (List of Numbers) Expected Output 1 1, 2, 3, 4, …

Neighbors of the same sign

Neighbors of the same sign. Given a list of numbers, find and print the first pair of adjacent elements that have the same sign. If no such pair exists, leave the output blank. Test Case Input (List of Numbers) Expected Output 1 1, -2, -3, 4 -2, -3 2 3, 5, -1, -2 3, 5 …

Greater than previous

Greater than previous. Given a list of numbers, find and print all the elements that are greater than the previous element in the list. Test Case Input (List of Numbers) Expected Output 1 1, 2, 1, 3, 2, 4 2, 3, 4 2 5, 3, 8, 6, 10, 2 8, 10 3 7, 9, 5, …

Even elements

Even elements. Given a list of numbers, find and print all elements that are even numbers. Use a for-loop that iterates directly over the list elements, not over their indices (i.e., do not use range()). Test Case Input (List of Numbers) Expected Output 1 1, 2, 3, 4, 5 2, 4 2 10, 15, 20, …

Even indices

Even indices. Given a list of numbers, find and print all the elements that are located at even index positions (i.e., A[0], A[2], A[4], …). Test Case Input (List of Numbers) Expected Output 1 1, 2, 3, 4, 5 1, 3, 5 2 10, 20, 30, 40, 50, 60 10, 30, 50 3 7, 14, …