This file contains 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
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; |
This file contains 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
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; |
This file contains 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 main | |
import ( | |
"fmt" | |
) | |
func getExtraElement(arrA []int, arrB []int) { | |
extraElement := 0 | |
for _, num := range arrA { |
This file contains 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
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) |
This file contains 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
function RPN (seq) { | |
if (seq.length <= 2) { | |
console.log('Please enter valid RPN'); | |
return; | |
} | |
let operands = ['+', '-', '*', '/' ], | |
stack = [], | |
i = 0; |
This file contains 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
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; |
This file contains 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
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; |
This file contains 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
var input = [{ | |
'name': 'event1', | |
'time': 1000 | |
}, { | |
'name': 'event2', | |
'time': 2000 | |
}, { | |
'name': 'event3', | |
'time': 3000 | |
}]; |
This file contains 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
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) | |
} | |
} |
This file contains 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
function add10 (a) { | |
return a + 10 | |
} | |
function compound (f) { | |
return function (b) { | |
return f(f(b)) | |
} | |
} |