Skip to content

Instantly share code, notes, and snippets.

@LuisitoRizado
LuisitoRizado / Viral Advertising challenge by Hackerrank
Created April 18, 2023 18:06
This is a solution for the 'Viral Advertising' Challenge by Hackerrank
function viralAdvertising(n) {
// Write your code here
let likesCounter = 0;
let start = 5;
for(let i = 0; i<n; i++){
if(start%2!=0){
console.log(start)
likesCounter += ((start/2)- 0.5)
start = ((start/2)-.5) * 3;
@LuisitoRizado
LuisitoRizado / Angry Professor Challenge by Hackerrank
Created April 17, 2023 20:16
This is a possible solution for the 'Angry Professor' Challenge by Hackerrank, you can use it for free
function angryProfessor(k, a) {
// Write your code here
let alumnsLate = 0;
//Lets travel the loop
//we've gotta travel the loop searching
//if the element (time) is higher than 0
//than would mean that the alumn was late
for(let i = 0; i<a.length; i++){
@LuisitoRizado
LuisitoRizado / Sales by Match Challenge
Created April 17, 2023 19:14
This is a solution for the 'Sales by Match' challenge by Hackerrank
function sockMerchant(n, ar) {
let socksPairs = 0 ;
let counter = 0;
let diferentNumbers = [];
//travel the array
for(let i = 0; i<ar.length; i++){
//esta omitiendo
if(!diferentNumbers.includes(ar[i])){
//agregarlo al arreglo de diferentes numeros
diferentNumbers.push(ar[i])
@LuisitoRizado
LuisitoRizado / Divisible Sum Pairs by Hackerrank
Created April 15, 2023 23:43
This is a solution for the 'Divisible sum pairs' by hackerrank
function divisibleSumPairs(n, k, ar) {
let sum = 0;
let pairs = 0;
//two loops
for(let i = 0; i<ar.length; i++){
//second loop
for(let j = i+1; j<ar.length; j++){
if((ar[i]+ar[j])%k==0){
pairs++;
}
@LuisitoRizado
LuisitoRizado / Breaking the records Hackerrank's challenge
Created April 15, 2023 03:54
This a solution for the 'Breaking the records' challenge by Hackerrank
function breakingRecords(scores) {
// Write your code here
let records = [0,0]
let best = scores[0];
let worst = scores[0];
let bestCounter = 0;
let worstCounter = 0;
//travel the array
scores.forEach(score=>{
//for each score, we have to compare
@LuisitoRizado
LuisitoRizado / Bill Division hackerrank's problem
Created April 12, 2023 04:17
This a possible solution for the 'Bill Division' problema by Hackerrank, you can use it for free
function bonAppetit(bill, k, b) {
// Write your code here
//bill is an array that contains all the items consumed
//k is the item anna didn't eat
//b is the amount of money Anna gave to Brian
let total = 0;
//splice the array
let newBill =bill.filter(element=> {
if(element!=bill[k]){
@LuisitoRizado
LuisitoRizado / Electronics Shop Hackerrank -Solution
Created April 7, 2023 04:07
This is a solution for the 'Electronics shop' Challenge by Hackerrank
function getMoneySpent(keyboards, drives, b) {
/*
* Write your code here.
*/
//Given an keyboards array an a drives array
//We've gotta find how many possibles
//'Combinations' are given a budget
//Example:
//keyboards = [40,25,30,60]
//drives = [10,12,14,7,18]
@LuisitoRizado
LuisitoRizado / Subarray Division Hackerrank
Created April 6, 2023 02:51
This a solution for the 'Subarray Division' challenge by Hackerrank, you can use it free
function birthday(s, d, m) {
// Write your code here
//we have to travel the array searching for the requirements
//EXAMPLE:
//s= [2,2,2,1,3,1]
//m = 2
//p = 4
//First: we travel the array searching i to i+m
let founds = 0;
let splicedArray;
function catAndMouse(x, y, z) {
let winner;
if(Math.abs(z-x) == Math.abs(z-y)){
//The Mouse scapes
winner = 'Mouse C'
}
else{
//Define a wineer (CAT A OR CAT B)
if(Math.abs(z-x)< Math.abs(z-y))
{
@LuisitoRizado
LuisitoRizado / Hackerrank 'Drawing book'
Created April 3, 2023 05:09
This is a solution for the 'Drawing book' problem by hackerrank. It was made in Javascript (Node js)
function pageCount(n, p) {
// Write your code here
//Identificar desde que lado empezaremos
let foundPage = false;
let currentPages = 0;
let counts = 0;
let tipoDeNumero = 0;
if(n%2!=0){
//Numero par = 0
//Numero impar = 1