Skip to content

Instantly share code, notes, and snippets.

View AlirezaInGitHub's full-sized avatar

AlirezaInGitHub

View GitHub Profile
ss://Y2hhY2hhMjAtaWV0Zi1wb2x5MTMwNTo0N3RtS0daNUJIcXo@35.209.198.215:80/?outline=1
/*
Sort A [a1..aN] where a1 <= aN. Then:
Case 1: A=[+, +, ..., +] || A=[-, -, ..., -] => Max = Product of the last three elements
Case 2: N= 3 => Only one product exists
Case 3: A=[-, -, ...., +] => Max = Product of the first and the last two elements
*/
function solution(A) {
let N = A.length;
A.sort((a,b) => (a-b));
return Math.max(A[0] * A[1] * A[N - 1], A[N - 1] * A[N - 2] * A[N - 3]);
// Solution 1:
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
let wests=[];
wests[A.length-1] = A[A.length-1]==1 ? 1 : 0;
for(let i=A.length-2; i>-1; i--)
{
wests[i] = wests[i+1];
if(A[i]==1)
wests[i]++;
function solution(A, B, K) {
// write your code in JavaScript (Node.js 8.9.4)
if(K==0) return 0;
const a = Math.floor(A/K);
const b = Math.floor(B/K);
if(a==0 && b==0 && B != 0)
return 0;
let between = b - a;
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const unique = [...new Set(A)].sort((x,y)=>x-y);
if(unique.length!=A.length) return 0;
for(let cntr=0; cntr<unique.length; cntr++)
if(cntr+1 != unique[cntr])
return 0;
return 1;
}
function solution(A) {
// write your code in JavaScript (Node.js 8.9.4)
const sorted = [...new Set(A)];
var positives = sorted.filter(p=>p>0).sort((x,y)=>x-y);
if(positives.length==0) return 1;
for(let cntr=0; cntr<positives.length; cntr++)
if(cntr+1 != positives[cntr])
return cntr+1;
return positives[positives.length-1] + 1;
}
function solution(N, A) {
var counters = new Array(N);
var max = 0;
var toBeAppliedMax = 0;
for (let K = 0; K < A.length; K++) {
const op = A[K];
if (op == N + 1) {
toBeAppliedMax = max;
@AlirezaInGitHub
AlirezaInGitHub / gist:8ca98a9090265c03f5744f590d8ddae3
Last active December 26, 2019 18:25
Docker: Install nodejs on Ubuntu
# To leverage layering, I've splitted the process into multiple lines:
RUN apt-get update
RUN apt-get install -y sudo
RUN apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN apt-get install -y nodejs nodejs
@AlirezaInGitHub
AlirezaInGitHub / React Advanced Pattern.md
Last active July 20, 2022 09:08
React advanced patterns

1. Compound Components

Compound Components pattern is grouping related components together in a way so that it becomes easier to read and more extensible.

Use case:

  • When we want to leave state management to a parent/container/enclosing component and leave the markup to the the user of the components

How?