Smart Mock Interview Logo
Get Started
easy
coding
Closest Number
Created by Smart Mock Interview

Given two integers n and m (m != 0). The problem is to find the number closest to n and divisible by m. If there is more than one such number, then output the one having the maximum absolute value.

Interview Questions

  1. Find the number closest to n and divisible by m
    coding

    Example:

    Input: n = 13, m = 4 Output: 12 Explanation: 12 is the Closest Number to 13 which is divisible by 4.

    Constraints:

    -105 ≤ n, m ≤ 105