We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Implementation
  4. Strange Counter

Strange Counter

Problem
Submissions
Leaderboard
Discussions
Editorial

There is a strange counter. At the first second, it displays the number . Each second, the number displayed by decrements by until it reaches . In next second, the timer resets to and continues counting down. The diagram below shows the counter values for each time in the first three cycles:

Find and print the value displayed by the counter at time .

Function Description

Complete the strangeCounter function in the editor below.

strangeCounter has the following parameter(s):

  • int t: an integer

Returns

  • int: the value displayed at time

Input Format

A single integer, the value of .

Constraints

Subtask

  • for of the maximum score.

Sample Input

4

Sample Output

6

Explanation

Time marks the beginning of the second cycle. It is double the number displayed at the beginning of the first cycle:. This is shown in the diagram in the problem statement.

Author

Shafaet

Difficulty

Easy

Max Score

30

Submitted By

74814

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy