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

Programming Exercises

Create a component that uses useMemo to optimize the rendering of a list of items by sorting them only when necessary.

Medium

Problem Statement

Create a component that uses useMemo to optimize the rendering of a list of items by sorting them only when necessary.

Sample Input

Initial list: [4, 2, 9, 1]

Sample Output

A sorted list is displayed only when the user clicks the 'Sort' button.

Limits

Time: 2s · Memory: 256 MB

Code Editor

Try your code in this preview. Submit marks it done.

import React, { useState, useMemo } from "react";
 
 const OptimizedSort = () => {
  return (
  <div>
  <button>Sort</button>
  <ul>
  {/* Render sorted items */}
  </ul>
  </div>
  );
 };
 
 export default OptimizedSort;