Giter VIP home page Giter VIP logo

prabaprakash / hackerrank-javascript-solutions Goto Github PK

View Code? Open in Web Editor NEW
119.0 3.0 62.0 160 KB

Solved entire Easy, few Medium Problems. A total of 171/563 challenges solved by JavaScript

Home Page: https://www.hackerrank.com/prabaprakash

JavaScript 97.21% Java 2.61% Python 0.19%
hackkerrank hackerrank-solutions hackerrank-algorithms-solutions hackerrank-challenges hackerrank-javascript problem-solving problemsolving es6 solutions leetcode-solutions

hackerrank-javascript-solutions's Introduction

Hackerrank-JS-Solutions

Solved entire easy problems & few medium problems in data structures category

one step at a time

Contributor

Contributors always welcome

hackerrank-javascript-solutions's People

Contributors

prabaprakash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hackerrank-javascript-solutions's Issues

High Value Palindrome

Algo

#include <bits/stdc++.h>

using namespace std;

string richieRich(string s, int n, int k){
   int lives=k;
   vector<bool> mod(n,false);  
   string temp(s); 
    
   for (int i=0;i<n/2;i++) 
   {
       if (temp[i]!=temp[n-i-1]) {mod[i]=true;lives--;}
       if (temp[i]<temp[n-i-1]) temp[i]=temp[n-i-1]; else if (temp[i]>temp[n-i-1]) temp[n-i-1]=temp[i];
       if (lives<0) return "-1";       
   }
    int j=0;
   while ((lives>0)&&(j<n/2))
   {
      if (temp[j]!='9'){
      if (mod[j]) lives++;
      if (lives>1) {temp[j]='9';temp[n-j-1]='9'; lives-=2;}
      }       
      j++;        
   }
    if (n%2==1) {if (lives>0) temp[n/2]='9';} 
    return temp;
}

int main() {
    int n;
    cin >> n;
    int k;
    cin >> k;
    string s;
    cin >> s;
    string result = richieRich(s, n, k);
    cout << result << endl;
    return 0;
}

Fibonacci Modified

big add
const add = (a, b) => {
    let carry = 0;
    let i = 0;
    for (i = 0; i < b.length; i++) {
        let n = a[i] + b[i] + carry;
        a[i] = n % 10;
        carry = Math.floor(n / 10);
    }
    while (carry > 0) {
        a[i] = typeof a[i] !== 'undefined' ? a[i] : 0
        let n = a[i] + carry;
        a[i] = n % 10;
        carry = Math.floor(n / 10);
        i++;
    }
    return a;
}
// big mul
const mul = (b, a) => {
    let out = [];
    let k = 0, carry = 0;
    for (let i = 0; i < a.length; i++) {
        for (let j = 0; j < b.length; j++) {
            let e = typeof out[k] !== 'undefined' ? out[k] : 0;
            let n = (a[i] * b[j]) + carry + e;
            out[k] = n % 10;
            carry = Math.floor(n / 10);
            k++;
        }
        if (carry > 0) {
            out[k] = carry;
            carry = 0;
        }
        k = i + 1;
    }
    return out;
}

Functional Programming Concepts

  1. this
  2. immutable data objects using a linter
  3. immutable objects and collections
  4. data transformations using core operations like filter, map, sort, or reduce
  5. use statements like if and switch in a functional way
  6. create pipelines and use currying to pass additional data
  7. create and use functors and monads

bst in js

let node = (data) => ({
  left: null,
  right: null,
  data: data
})
let bst = {
  root: null,
  insert: (root = bst.root, data) => {
    if (root === null) {
      bst.root = node(data);
    } else {
      if (data < root.data) {
        root.left = root.left === null ? node(data) : bst.insert(root.left, data);
      }
      else {
        root.right = root.right === null ? node(data) : bst.insert(root.right, data);
      }
    }
    return root;
  },
  postorder: (root) => {
    if (root !== null) {
      bst.postorder(root.left);
      bst.postorder(root.right);
      console.log(root.data);
    }
  },
  inorder: (root) => {
    if (root !== null) {
      bst.inorder(root.left);
      console.log(root.data);
      bst.inorder(root.right);
    }
  },
  remove: (root, data) => {
    if (root === null) return null;
    else if (data > root.data) {
      root.right = bst.remove(root.right, data);
      return root;
    }
    else if (data < root.data) {
      root.left = bst.remove(root.left, data);
      return root;
    }
    else {

      if (root.left == null && root.right === null) {
        root = null;
        return root;
      }
      if (root.left === null) {
        root = root.right;
        return root;
      }
      else if (root.right === null) {
        root = root.left;
        return root;
      }

      // Deleting node with two children 
      // minumum node of the rigt subtree 
      // is stored in aux 
      let aux = bst.findMinNode(root.right);
      root.data = aux.data;

      root.right = bst.remove(root.right, aux.data);
      return root;
    }
  },
  findMinNode: (root) =>{
     if(root.left === null) return root;
     root = bst.findMinNode(root.left);
     return root;
  }
}


bst.insert(bst.root, 15);
bst.insert(bst.root, 25);
bst.insert(bst.root, 10);
bst.insert(bst.root, 7);
bst.insert(bst.root, 22);
bst.insert(bst.root, 17);
bst.insert(bst.root, 13);
bst.insert(bst.root, 5);
bst.insert(bst.root, 9);
bst.insert(bst.root, 27);

console.log(JSON.stringify(bst.root));

bst.remove(bst.root, 5);


bst.remove(bst.root, 7);
// bst.inorder(bst.root);

bst.remove(bst.root, 15);
bst.inorder(bst.root);

Maximum Palindromes

Algorithms to solve it,

  1. Modular multiplicative inverse
  2. Combinatorics and Permutation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.