Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Valeri quenchaman

🏠
Working from home
View GitHub Profile
View binary_search.c
#include <stdio.h>
int binary_search(int arr[], size_t start, size_t end, int needle) {
if (start > end) {
return -1;
}
size_t mid = start + ((end - start) / 2);
if (arr[mid] == needle) {
@quenchaman
quenchaman / LevelMap.java
Created Dec 14, 2020
Creates a map where keys are the levels in the map and the nodes are in a list
View LevelMap.java
public static Map<Integer, List<TreeNode>> getTreeLevels(TreeNode root) {
Map<Integer, List<TreeNode>> treeLevels = new HashMap<>();
DFS(root, 0, treeLevels);
return treeLevels;
}
public static void DFS(TreeNode root, int level, Map<Integer, List<TreeNode>> levelMap) {
if (root == null) {
@quenchaman
quenchaman / areChildren.java
Created Dec 14, 2020
Finds if the first parameter 'root' node is parent to all nodes in the list
View areChildren.java
/*
Find the common nodes between multiple nodes
*/
public static boolean allNodesChildren(TreeNode root, List<TreeNode> nodes) {
for (TreeNode node : nodes) {
TreeNode common = findCommonNode(root, root, node);
if (common == null) {
return false;
}
@quenchaman
quenchaman / FindCommonNode.java
Created Dec 14, 2020
Finding a 'smallest' common node in a tree
View FindCommonNode.java
public static TreeNode findCommonNode(TreeNode root, TreeNode node1, TreeNode node2) {
if (root == null) {
return null;
}
TreeNode foundInLeft = findCommonNode(root.left, node1, node2);
if (foundInLeft != null) {
return foundInLeft;
}
View test-sum-1.java
package io.kubeless;
import io.kubeless.Event;
import io.kubeless.Context;
public class test-sum-1 {
public String main(io.kubeless.Event event, io.kubeless.Context context) {
return "Hello world!";
}
}
View 16diagonals.py
empty_cell = -1
right_diag = 0
left_diag = 1
grid_width = grid_height = 3
target = 6
top_left_corner_offset = 0
top_right_corner_offset = 1
bottom_right_corner_offset = 5
bottom_left_corner_offset = 4
View index.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>AnimalShelter</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
View concatenate.js
const fs = require('fs-extra');
const concat = require('concat');
(async function build() {
const fileNames = ['runtime', 'polyfills', 'main', 'styles'];
const jsVersion = ['es5', 'es2015'];
const pathToFiles = './dist/animal-list';
const files = [];
fileNames.forEach(fn => {
jsVersion.forEach(jsver => {
View app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgbCarouselModule } from '@ng-bootstrap/ng-bootstrap';
import { HttpClientModule } from '@angular/common/http';
import { Injector } from '@angular/core';
import { createCustomElement } from '@angular/elements';
import { AppComponent } from './app.component';
import { AnimalListComponent } from './components/animal-list/animal-list.component';
View animal-list.component.html
<ngb-carousel *ngIf="animals.length">
<ng-template ngbSlide *ngFor="let animal of animals">
<div class="picsum-img-wrapper">
<img [src]="animal.thumbnail" alt="Animal" width="100%">
</div>
<div class="carousel-caption">
<h3>{{ animal.name }}</h3>
<p>{{ animal.species }}</p>
</div>
</ng-template>