This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//arr=000110010 | |
let arr = [0,0,0,0,0,1,1,0,0,0,0,0,0,1]; | |
//let arr = [0,0,0,0,0] | |
const getMaxZero = (arr) => { | |
if(arr && arr[0] == 0 && arr[arr.length-1] == 0) { | |
//first non one |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
//String[] nums = {"1", "2", "4", "4", "5"}; | |
String[] nums = {"4", "4", "4"}; | |
//String[] nums = {"-214748364801","-214748364802"}; | |
int k = 2; //second largest element | |
long l = findKthLargest( getUniqArray(nums), k); | |
System.out.println(l); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let double = x => true | |
let triple = x => x ? 6 : 7 | |
let quadruple = x => x * 4 | |
let pipe = (...funs) => input => funs.reduce( | |
(total, fn) => { | |
console.log(fn, '-----',total) | |
return fn(total) | |
}, | |
input |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node { | |
constructor(key, value) { | |
this.key = key; | |
this.value = value; | |
this.next = null; | |
this.prev = null; | |
} | |
} | |
class LRU { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Given an array of strictly the characters 'R', 'G', and 'B', | |
* segregate the values of the array so that all the Rs come first, | |
* the Gs come second, and the Bs come last. | |
* You can only swap elements of the array. | |
* | |
* Do this in linear time and in-place. | |
* | |
* For example, given the array ['G', 'B', 'R', 'R', 'B', 'R', 'G'], | |
* it should become ['R', 'R', 'R', 'G', 'G', 'B', 'B']. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Case: 1 | |
Input: 2 | |
Output: 2 | |
Explanation: There are two ways to climb to the top. | |
1. 1 step + 1 step | |
2. 2 steps | |
Case: 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For example, given x = 10 and lst = [9, 12, 3, 5, 14, 10, 10] | |
let lst = [9, 12, 3, 5, 14, 10, 10] | |
const sanitizePivot = (lst, pivot) => { | |
let start = 0, end = lst.length -1 | |
while(start<end) { | |
if(lst[start] == pivot) { | |
let _e = end; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const printPascal= (noOfRows) => { | |
let coef = 1 | |
let ret = '' | |
for (let i = 0; i< noOfRows; i++) { | |
for (let space = 1 ; space <= noOfRows-i; space++) { | |
ret += ' ' | |
} | |
for (let j =0; j<= i; j++) { | |
if ( j ==0 || i == 1) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func GetAllUsers(c *fiber.Ctx) { | |
var users []models.User | |
//Connection mongoDB with helper class | |
collection := helper.ConnectDB("users") | |
// bson.M{}, we passed empty filter. So we want to get all data. | |
cur, err := collection.Find(context.TODO(), bson.M{}) | |
if err != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package controllers | |
import ( | |
"context" | |
"log" | |
"github.com/gofiber/fiber" | |
"github.com/vbanurag/go-fiber/helper" | |
"github.com/vbanurag/go-fiber/models" | |
"go.mongodb.org/mongo-driver/bson" |
NewerOlder