Skip to content
Discussion options

You must be logged in to vote

We need to determine the final value of a variable X after performing a series of operations. The operations can either increment or decrement the value of X by 1. The operations are given as an array of strings, each string being one of the following: "++X", "X++", "--X", or "X--". The initial value of X is 0.

Approach

  1. Initialization: Start with X set to 0.
  2. Operation Processing: For each operation in the array, check whether it is an increment or decrement operation. This can be determined by examining the second character of each operation string. If the second character is +, it indicates an increment operation; if it is -, it indicates a decrement operation.
  3. Update Value: Based on th…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@basharul-siddike
Comment options

@mah-shamim
Comment options

mah-shamim Oct 20, 2025
Maintainer Author

Answer selected by basharul-siddike
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants