Skip to content

Latest Updates

CodeForces/problems/112/112A.js

let input = require('fs').readFileSync(0,'utf8').split(/\r?\n/);
console.log( input[0].toLowerCase().localeCompare(input[1].toLowerCase() ) );

CodeForces/problems/263/263A.js

let input = require('fs').readFileSync(0,'utf8').trim().split(/\r?\n/).map( (row)=>row.split(" "));
for(let row = 0; row<5; row++){
for(let col = 0; col<5; col++){
if(input[row][col] == '1'){
console.log( Math.abs( Math.abs(2-row)+Math.abs(2-col) ) );
break;
}
}
}

LeetCode/problems/1437-check-if-all-1s-are-at-least-length-k-places-away/1437-check-if-all-1s-are-at-least-length-k-places-away.js

/**
* @param {number[]} nums
* @param {number} k
* @return {boolean}
*/
var kLengthApart = function(nums, k) {
let prev = -1;
for(let I = 0; I<nums.length; I++){
if( nums[I] == 1 ){
if( prev >= 0 && I-prev-1 < k){
return false;
}
prev = I;
}
}
return true;
};

LeetCode/problems/1502-can-make-arithmetic-progression-from-sequence/1502-can-make-arithmetic-progression-from-sequence.js

/**
* @param {number[]} arr
* @return {boolean}
*/
var canMakeArithmeticProgression = function(arr) {
arr.sort( (a,b)=>a-b);
let blah = arr[1]-arr[0];
for(let I = 1; I<arr.length; I++){
if(arr[I]-arr[I-1] !== blah){return false}
}
return true;
};

LeetCode/problems/2485-find-the-pivot-integer/2485-find-the-pivot-integer.js

/**
* @param {number} n
* @return {number}
*/
var pivotInteger = function(n) {
const AS = (x)=>(x/2)*(x+1);
if(n==1){return 1;}
for(let I = 1; I<n; I++){
if( AS(I) == AS(n)-AS(I-1)){
return I;
}
}
return -1;
};

LeetCode/problems/7-reverse-integer/7-reverse-integer.js

/**
* @param {number} x
* @return {number}
*/
var reverse = function(x) {
let blah = 0;
let sign = Math.sign(x);
x = Math.abs(x);
while(x > 0){
blah = blah*10 + x%10;
x = Math.floor(x/10);
}
if(blah > (2**31) - 1){ return 0; }
return sign*blah;
};