Back to Interview Prep

Warm Up · Star Pattern

n×n Star Square

Problem Statement

Print a square pattern of stars (*) of size n x n.

Output

****
****
****
****

Approach

  • Outer Loop (Rows): Run from i = 0 to i = n - 1.
  • Inner Loop (Columns): For each row, loop from j = 0 to j = n - 1.
  • Build Row String: Append * in each inner loop iteration.
  • Print Row: After the inner loop, print the complete row string.

Time & Space Complexity

Time Complexity: O(n^2)

Space Complexity: O(n) (temporary row string)

Your solution

Solve it in JavaScript and print the answer with console.log(). Run to see your output, then Submit to check it against the test cases.

// Write your solution in JavaScript
// Print the answer with console.log()


Console

No output yet. Use console.log() to print values here.

Write your own solution and press Submit once to unlock the answer.

You're viewing a free lesson. Sign up free to track your progress and unlock the full course.Sign up freeSign in