Solved entire easy problems & few medium problems in data structures category
Contributors always welcome
Solved entire Easy, few Medium Problems. A total of 171/563 challenges solved by JavaScript
Home Page: https://www.hackerrank.com/prabaprakash
Need more focus on Dynamic Programming
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;
}
Please list possible algo for solving these problems
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;
}
Algorithm Explained: https://medium.com/@leejh3224/hackerrank-solution-almost-sorted-4331bd58275
Case 1: Valley === 1
No
Case 2: Valley === Peak === 1
swap, then the array is sorted
or
reverse, then the array is sorted
case 3: Valley > 1, Peak > 1
no
case 4: Valley === Peak === 0
reverse, then the array is sorted
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);
Algorithms to solve it,
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.