MeetCode
Round To Nearest Multiple
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Run
Submit
Dark
Problem Statement
Solutions
Submissions
Round To Nearest Multiple
Hard
Computer Mathematics
Integers & Divisibility
20 views
Explanation
Complexity
Problem Statement
Given n and k>0, round n to nearest multiple of k (ties go up).
Input Format
Two integers n k.
Output Format
Rounded multiple.
Example
Input
14 5
Output
15
Constraints
k>0
Input / Output Format
Input Format
Two integers n k.
Output Format
Rounded multiple.
Constraints
k>0
Examples
Input:
14 5
Output:
15
Example Solution (Public)
Computer Mathematics
Compute down = floor(n/k)*k. up = down+k. Compare distances. If equal choose up.
Official Solution Code
Wrap
Copy
Compute down = floor(n/k)*k. up = down+k. Compare distances. If equal choose up.
Please
login
to submit solutions.
Editor
C
C++
Computer Mathematics
CSS
DSA
HTML
Java
JavaScript
NodeJS
PHP
Programming Interview
Python
ReactJS
SQL
Test Cases
Output
Submission Result
Input
14 5
Expected Output
15
Compile Output
Error
Output
Please
login
to submit solutions.