Skip to content

Instantly share code, notes, and snippets.

Anderson Leite andersonleite

Block or report user

Report or block andersonleite

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View cryptarithm.js
// A cryptarithm is a mathematical puzzle for which the goal is to find the correspondence between letters and digits, such that the given arithmetic equation consisting of letters holds true when the letters are converted to digits.
// You have an array of strings crypt, the cryptarithm, and an an array containing the mapping of letters and digits, solution. The array crypt will contain three non-empty strings that follow the structure: [word1, word2, word3], which should be interpreted as the word1 + word2 = word3 cryptarithm.
// If crypt, when it is decoded by replacing all of the letters in the cryptarithm with digits using the mapping in solution, becomes a valid arithmetic equation containing no numbers with leading zeroes, the answer is true. If it does not become a valid arithmetic solution, the answer is false.
// Note that number 0 doesn't contain leading zeroes (while for example 00 or 0123 do).
// Example
View sudoku.js
// Sudoku is a number-placement puzzle. The objective is to fill a 9 × 9 grid with numbers in such a way that each column, each row, and each of the nine 3 × 3 sub-grids that compose the grid all contain all of the numbers from 1 to 9 one time.
// Implement an algorithm that will check whether the given grid of numbers represents a valid Sudoku puzzle according to the layout rules described above. Note that the puzzle represented by grid does not have to be solvable.
// Example
// For
// grid = [['.', '.', '.', '1', '4', '.', '.', '2', '.'],
// ['.', '.', '6', '.', '.', '.', '.', '.', '.'],
View containsCloseNums.js
// Given an array of integers nums and an integer k, determine whether there are two distinct indices i and j in the array where nums[i] = nums[j] and the absolute difference between i and j is less than or equal to k.
// Example
// For nums = [0, 1, 2, 3, 5, 2] and k = 3, the output should be
// containsCloseNums(nums, k) = true.
// There are two 2s in nums, and the absolute difference between their positions is exactly 3.
// For nums = [0, 1, 2, 3, 5, 2] and k = 2, the output should be
@andersonleite
andersonleite / areFollowingPatterns.js
Created Jul 16, 2019
Determine whether it follows the sequence given in the patterns array
View areFollowingPatterns.js
// Given an array strings, determine whether it follows the sequence given in the patterns array. In other words, there should be no i and j for which strings[i] = strings[j] and patterns[i] ≠ patterns[j] or for which strings[i] ≠ strings[j] and patterns[i] = patterns[j].
function areFollowingPatterns(strings, patterns) {
let sHash = {}
let pHash = {}
let counter = 0
let pat1 = ''
View dishes.js
// You are given a list dishes, where each element consists of a list of strings beginning with the name of the dish, followed by all the ingredients used in preparing it. You want to group the dishes by ingredients, so that for each ingredient you'll be able to find all the dishes that contain it (if there are at least 2 such dishes).
// Return an array where each element is a list beginning with the ingredient name, followed by the names of all the dishes that contain this ingredient. The dishes inside each list should be sorted lexicographically, and the result array should be sorted lexicographically by the names of the ingredients.
function groupingDishes(dishes) {
let hash = {}
dishes.forEach((dish)=>{
let name = dish[0]
@andersonleite
andersonleite / removeKFromList.js
Last active Jul 14, 2019
Remove all elements from list l that have a value equal to k
View removeKFromList.js
// Note: Try to solve this task in O(n) time using O(1) additional space, where n is the number of elements in the list, since this is what you'll be asked to do during an interview.
// Given a singly linked list of integers l and an integer k, remove all elements from list l that have a value equal to k.
// Example
// For l = [3, 1, 2, 3, 4, 5] and k = 3, the output should be
// removeKFromList(l, k) = [1, 2, 4, 5];
// For l = [1, 2, 3, 4, 5, 6, 7] and k = 10, the output should be
// removeKFromList(l, k) = [1, 2, 3, 4, 5, 6, 7].
@andersonleite
andersonleite / Albie.js
Last active Jul 14, 2019 — forked from mauricioaniche/Albie.java
Reverse Nodes In K Groups
View Albie.js
// Singly-linked lists are already defined with this interface:
// function ListNode(x) {
// this.value = x;
// this.next = null;
// }
//
function reverseNodesInKGroups(l, k) {
return calculate(l, k , Math.floor(sizeOf(l)/k))
}
View jumps.js
/**
You are given an array of integers representing coordinates of obstacles situated on a straight line.
Assume that you are jumping from the point with coordinate 0 to the right. You are allowed only to make jumps of the same length represented by some integer.
Find the minimal length of the jump enough to avoid all the obstacles.
Example
For inputArray = [5, 3, 6, 7, 9], the output should be avoidObstacles(inputArray) = 4.
@andersonleite
andersonleite / test.ts
Created Aug 22, 2018
Testing components
View test.ts
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { AnalyticsSelectorComponent } from './analytics-selector.component';
import { MatFormFieldModule, MatInputModule } from '@angular/material';
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
describe('AnalyticsSelectorComponent', () => {
let component: AnalyticsSelectorComponent;
let fixture: ComponentFixture<AnalyticsSelectorComponent>;
View chat.css
@charset "UTF-8";
/*!
* Bootstrap v3.3.5 (http://getbootstrap.com)
* Copyright 2011-2015 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
*/
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */
html {
font-family: sans-serif;
-ms-text-size-adjust: 100%;
You can’t perform that action at this time.