Top-Level JSON Array Split

JavaScript Hard 5 views
Back to Questions

Problem Description

One line has a JSON array as plain text (do NOT parse). Count how many top-level elements are present, ignoring commas inside strings/brackets. Print the count.

Input Format

One line JSON array text.

Output Format

One integer count.

Sample Test Case

Input:
[1,2,[3,4],{"a":5},"x,y"]
Output:
5

Constraints

Input is valid JSON array text. Length up to 2e5.

Solutions (0)

No solutions submitted yet. Be the first!

Discussion (0)

No comments yet. Start the discussion!

Prev Next