Count Occurrence of X
JavaScript
Easy
6 views
Problem Description
Given array and number x, count how many times x appears.
Input Format
Line1: n x. Line2: n integers.
Output Format
One integer count.
Sample Test Case
Input:
8 3
3 1 3 3 2 3 9 3
Official Solution
const fs=require('fs');const s=fs.readFileSync(0,'utf8').trim();if(!s)process.exit(0);const a=s.split(/\\s+/);let i=0;const n=Number(a[i++]);const x=a[i++];let c=0;for(let j=0;j<n;j++){if(a[i++]===x)c++;}process.stdout.write(String(c));
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!