Skip to content

Instantly share code, notes, and snippets.

farnasirim /
Created December 8, 2019 19:29
Solution to Surrounded Regions



We have to find all regions of O's that are surrounded by X's, and convert them to X's.

The most trivial approach here would be taking every cell that contains an O, and checking to see whether or not it is connected to at least one of the borders through other O cells. If this is the case, that cell is not surrounded. Otherwise that cell is part of a (possibly large) surrounded region and has to marked with X:

farnasirim / ternary_on_integer_domain.cpp
Last active December 8, 2019 17:05
Ternary search on integer domain + test drive
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
using namespace std;
template <typename Compare>
int findMax(int from, int to, Compare lessFunctor) { // from and to are inclusive: [from, to]
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="">
<script src="" charset="utf-8"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<div style="max-width:800px; -webkit-transform:rotate(0deg)">
<scene width="600" id="scene1">
<label t="translate(0,346)">
farnasirim / .vimrc
Created December 16, 2017 14:52
Poor man's .vimrc
set ts=4
set sw=4
set smartindent
set ai
set background=dark
colorscheme slate
syntax enable
set nocompatible
filetype plugin indent on
set hlsearch
farnasirim /
Last active November 2, 2017 09:28
navigate to a go project directory easily using `goto` command
if [ -z "$@" ]; then
echo "Usage: goto project-name"
for i in {1..3}; do