Skip to content

Instantly share code, notes, and snippets.

import java.util.Arrays;
class Job {
int start_time;
int end_time;
int weight;
public Job(int start_time, int end_time, int weight) {
this.start_time = start_time;
this.end_time = end_time;
import java.util.HashMap;
public class longestCommonString {
public static int find(String s1, String s2, HashMap<String, Integer> map){
if (s1 == null || s1.length() ==0)
return 0;
if (s2 == null || s2.length() ==0)
return 0;
package main
import (
"fmt"
)
func getExtraElement(arrA []int, arrB []int) {
extraElement := 0
for _, num := range arrA {
def get_extra_element(arrA, arrB):
extra_element = 0
for num in arrA:
extra_element ^= num
for num in arrB:
extra_element ^= num
print("Array A:", arrA)
function RPN (seq) {
if (seq.length <= 2) {
console.log('Please enter valid RPN');
return;
}
let operands = ['+', '-', '*', '/' ],
stack = [],
i = 0;
function mergeTwoSortedLists (l1, l2) {
let mergedLinkedListHead = { val : -1, next : null }; // create dummy node to get started
let runner = mergedLinkedListHead;
while(l1 && l2) {
if(l1.val > l2.val) {
runner.next = l2;
l2 = l2.next;
function findFirstUniqueCharacter( inputString ) {
let freqCounter = [];
// The issue using Map data structure is during the retrival. As it does not gaurantee the keys will be retrived in the same order as they were inserted
// Hence, we use an array of frequency counter. But in this array keys are found using the ascii values of the character.
inputString.split('').forEach(ch => {
if (!freqCounter[ch])
freqCounter[ch] = 1;
var input = [{
'name': 'event1',
'time': 1000
}, {
'name': 'event2',
'time': 2000
}, {
'name': 'event3',
'time': 3000
}];
Function.prototype.bind1 = function (scope) {
let fn = this
let prefixArgs = Array.prototype.slice.call(arguments, 1)
return function() {
let suffixArgs = Array.prototype.slice.call(arguments)
let args = prefixArgs.concat(suffixArgs)
return fn.apply(scope, args)
}
}
function add10 (a) {
return a + 10
}
function compound (f) {
return function (b) {
return f(f(b))
}
}