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

Programming Exercises

Implement a function that converts a given JSON object to a query string.

Hard

Problem Statement

Implement a function that converts a given JSON object to a query string.

Sample Input

{
 name: "John Doe",
 age: 30,
 city: "New York" }

Sample Output

name=John%20Doe&age=30&city=New%20York

Limits

Time: 2s · Memory: 256 MB

Code Editor
00:00
function toQueryString(obj) { // Map object keys and values to key=value pairs // Use encodeURIComponent to handle special characters } const params = { name: "John Doe", age: 30, city: "New York" }; console.log(toQueryString(params));
Log in or sign up to run or submit your code.Log inSign up
Input
{
 name: "John Doe",
 age: 30,
 city: "New York" }
Expected Output
name=John%20Doe&age=30&city=New%20York