Answer: ENTRI Hiring | Online Assessment Question | On-Campus (2023)

Answer · Posted Jun 2026

Approach We only need to determine whether an operation increments or decrements the variable. If the operation contains '+', increase X by 1. Otherwise, decrease X by 1. After processing all operations, return the final value. Strategy Initialize x = 0. Traverse each operation string. Check whether it contains '+'. Increment or decrement accordingly. Return x. Java Code class Solution { public int finalValueAfterOperations(String[] operations) { int x = 0; for (String op : operations) { if (op.contains("+")) x++; else ...

The full answer & interview discussion are available to premium members.

Log in Create a free account