Posts

Showing posts from March, 2023

countfirst1.js

Image
  /*Count first You have been given a sequence of n integers. Lets say the given sequence is a0, a1, a2, a3 ... an-1. You need to find the number of occurrences of the first value (i.e. a0) in the given sequence. Input Format: First line contains an integer n, denoting the length of the sequence. Next n lines contains one integer each. Output Format: One integer, denoting the result, as mentioned above. Example: Input: 5 10 20 30 40 10 Output: 2 Explanation: First line contains 5, meaning the sequence has 5 integers. First element is 10. In the given sequence, 10 occurs 2 times. So, the output is 2. */ let fs = require ( "fs" ); let data = fs . readFileSync ( 0 , 'utf-8' ); let idx = 0 ; data = data. split ( ' \n ' ); function readLine () { idx ++ ; return data[idx - 1 ]. trim (); } //====================================================================================================== let noOfInputs = parseInt ( readLine ()); // 5 let ...

amazingsum.js

Image
  /*Amazing Sum You have been given n integer values. Lets say the given values are [latex]a_1[/latex], [latex]a_2[/latex], [latex]a_3[/latex], [latex]a_4[/latex] ... [latex]a_n[/latex] If the sum of two consecutive input values is greater than 100, then the given values have amazing sum Input Format: First line denotes n, the number of inputs. The next n lines contains one integer in each line. Output Format: One string, either true or false, denoting whether the given values has amazing sum or not. Example: Input: 5 20 12 23 41 17 Output: false Explanation: The maximum sum of two consecutive values here is 64 (i.e. 23 + 41), which is not greater than 100, so the answer is false. */ let fs = require ( "fs" ); let data = fs . readFileSync ( 0 , 'utf-8' ); let idx = 0 ; data = data. split ( ' \n ' ); function readLine () { idx ++ ; return data[idx - 1 ]. trim (); } //==========================================================================...