{{ message }}

Instantly share code, notes, and snippets.

# Tomasz Baranowicz tombaranowicz

Created May 10, 2017
Simple Starter for experiments with Genetic Algorithms in Swift
View GeneticAlgorithm.swift
 //: Simple Genetic Algorithm Starter in Swift 3 import UIKit import Foundation let AVAILABLE_GENES:[Int] = Array(1...100) let DNA_LENGTH = 6 let TOURNAMENT_SIZE = 5 let MAX_GENERATIONS_COUNT = 100
Created Aug 7, 2019
2 ways of solving "Two Sum" coding interview problem in JavaScript.
View twoSum.js
 // var twoSum = function(nums, target) { // for(index = 0; index < nums.length - 1; index++) { // for(i = index+1; i< nums.length; i++) { // let sum = nums[index] + nums[i]; // if (sum == target) { // return [index, i]; // } // } // } // };
Created Aug 16, 2019
"Add Two Numbers" leetcode coding interview problem & solution
 function ListNode(val) { this.val = val; this.next = null; } /** * @param {ListNode} l1 * @param {ListNode} l2 * @return {ListNode}
Created Oct 12, 2019
Google Coding Interviews Number of Islands (LeetCode) and explanation. One of Google's most commonly asked interview questions according to LeetCode. This coding interview question is commonly asked by companies like: Google, Facebook, Snapchat, Amazon, Uber, LinkedIn, Microsoft, Apple and many others.
View numberOfIslands.js
 /** * @param {character[][]} grid * @return {number} */ var dfs = function(grid, i, j) { const w = grid.length; const h = grid[0].length;
Created Dec 6, 2019
Swift Collections - Dictionary
View SwiftCollectionsDictionary.swift
 //DICTIONARIES //1. Create //IMMUTABLE (size and contents cannot be changed) let immutableResponseMessages = [200: "OK", 403: "Access forbidden", 404: "File not found", 500: "Internal server error"]
Created Dec 12, 2019
Swift Collections - Set
View SwiftCollectionsSet.swift
 //SETS //CREATE //immutable - using array literal let mazdas: Set = ["2", "3", "3", "6", "CX-3", "CX-5", "CX-9", "MX-5", "CX-30"] let oldMazdas: Set oldMazdas = ["323", "626"]
Created Dec 19, 2019
Swift Collections - Array
View SwiftCollectionsArray.swift
 import Foundation //CREATE //declaration using type annotation syntax (arrays are strongly typed) let stringArray : Array //initialiser syntax uses type inference mechanism var intArray = Array() let shorterIntArray = [Int]()
Created Sep 13, 2019
2 ways of solving "Longest Substring Without Repeating Characters" problem in JavaScript
View longestSubstringWithoutRepeatingCharacters.js
 // //BRUTE FORCE METHOD // var lengthOfLongestSubstring = function(s) { // let count = 0; // for (let i=0; i< s.length; i++) { // let char = s.charAt(i); // let set = new Set([char]); // for (let j=i+1; j
Created Sep 26, 2019
How To Solve LeetCode Longest Palindromic Substring Problem With JavaScript
View longestPalindromicSubstring.js
 // OPTIMIZED function expandAroundCenterSolution(s) { let start = 0, end = 0; for (let i = 0; i < s.length; i++) { let center = getCenter(s, i); let bounds = expandAroundCenter(s, center[0], center[1]); let L = bounds[0], R = bounds[1]; if (R - L > end - start) { start = L; end = R;