Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests

Programming Exercises

Write a function that converts a number to a string in any base (e.g., base 2, base 16).

Hard

Problem Statement

Write a function that converts a number to a string in any base (e.g., base 2, base 16).

Sample Input

num = 255, base = 16

Sample Output

ff

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
// Convert a number to a string in any specified base function convertToBase(num, base) { // Use division and modulo operations to convert to the specified base } console.log(convertToBase(255, 16));
Log in or sign up to run or submit your code.Log inSign up
Input
num = 255, base = 16
Expected Output
ff