Remove All X
JavaScript
Easy
4 views
Problem Description
Array se value x ko jitni baar bhi aayi hai, sab hata do. Baaki order same rehna chahiye. Print new length and new array.
Input Format
Line1: n x. Line2: n integers.
Output Format
Line1: newLength. Line2: updated array (or empty).
Official Solution
const fs=require('fs');const raw=fs.readFileSync(0,'utf8').trim();if(!raw)process.exit(0);const parts=raw.split(/\\s+/);let i=0;const n=Number(parts[i++]);const x=parts[i++];let out=[];for(let j=0;j<n;j++){const v=parts[i++];if(v!==x)out.push(v);}let res=String(out.length);if(out.length)res+='\
'+out.join(' ');process.stdout.write(res);
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!