Skip to content

Instantly share code, notes, and snippets.

View hawaijar's full-sized avatar
🎯
Focusing

Mayengbam Sushil K hawaijar

🎯
Focusing
View GitHub Profile
const ROMAN_MAPPING = {
1: 'I',
5: 'V',
10: 'X',
50: 'L',
100: 'C',
500: 'D',
1000: 'M',
4: 'IV',
9: 'IX',
@hawaijar
hawaijar / minHeap.js
Created April 24, 2021 13:59
Implementing min-heap
class Heap {
constructor() {
this.container = [];
}
getLeftChildIndex(parentIndex) {
return 2 * parentIndex + 1;
}
getRightChildIndex(parentIndex) {
return 2 * parentIndex + 2;
}
@hawaijar
hawaijar / lru.js
Created May 13, 2021 05:43
Simple LRU cache using only Array
const LRUCache = function (capacity) {
this.cache = [];
this.capacity = capacity;
this.count = 0;
};
LRUCache.prototype.get = function (key) {
const obj = this.cache.find((item) => item.key === key);
if (obj) {
this.cache = this.cache.filter((item) => item.key !== key);
this.cache.push(obj);
@hawaijar
hawaijar / lruII.js
Created May 13, 2021 14:49
LRU implementation using hash and list
const Node = function (key, value) {
this.key = key;
this.value = value;
this.next = null;
this.previous = null;
};
const LRUCache = function (capacity) {
this.head = null;
this.tail = null;
@hawaijar
hawaijar / stringMatcher.js
Created October 3, 2021 01:51
Smallest substring containing a sequece of characters.
// point 1: Create a hash to capture the characteristics of the 'smallString' - what are the chars and count of its char
// Use two pointers (left & right - initially pointing to the start of 'bigString' ) and start scanning from left to right
/**
*
* @param h1 (bigger string)
* @param h2 (smaller string)
* @return {boolean}
*/
function hashesMatching(h1, h2) {
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
char charData = 'A';
printf("\nSize of variable charData is %lu byte", sizeof(charData));
int intData = 100;
printf("\nSize of variable intData is %lu bytes", sizeof(intData));
short shortIntData = 20;
printf("\nSize of variable shortIntData is %lu bytes", sizeof(shortIntData));
#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
BOOL isRaining = true;
if(isRaining) {
printf("Get Umbrellla");
}
else {
NS_ASSUME_NONNULL_BEGIN
@interface Movie : NSObject {
NSString* name;
NSInteger year;
NSInteger rating;
}
- (void)setName:(NSString*) movieName;
- (void)setYear:(NSInteger) releaseYear;
#import "Movie.h"
@implementation Movie
- (void)setName:(NSString *)movieName {
name = movieName;
}
- (void)setYear:(NSInteger)releaseYear {
year = releaseYear;
}
import UIKit
import XCTest
struct LoggedInUser {
let name: String
}
class LoginViewController: UIViewController {
var login: (((LoggedInUser) -> Void) -> Void)?
var user: String?