Skip to content

Instantly share code, notes, and snippets.

View jboursiquot's full-sized avatar
👾

Johnny Boursiquot jboursiquot

👾
View GitHub Profile

Two-Number Sum

Write a function that takes as parameters a non-empty slice of integers and an integer representing a target sum. Your task is to return the pair of numbers within the input slice that add up to the target sum given. If no numbers in the input slice add up to the given target sum, return an empty slice. You may assume that there will be no more than one pair of numbers from the input slice that add up to the target sum.

Hint: There are several ways to do this which vary in efficiency. First focus on solving it and only then on optimizing it.

You may use the test below to exercise your solution.

Bubble Sort

Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list, compares adjacent pairs and swaps them if they are in the wrong order. The pass through the list is repeated until the list is sorted. The algorithm, which is a comparison sort, is named for the way smaller or larger elements "bubble" to the top of the list. -- Wikipedia (https://en.wikipedia.org/wiki/Bubble_sort)

Create a function, bubleSort, that takes a list of integers and sorts them in non-decreasing order using a bubble sort algorithm.

For example:

Non-repeating character in a string

Write a function that takes a string and returns the first character in it that does not repeat two or more times.

Example:

nonRepeating("abcba") // should return "c"
nonRepeating("ddgTwWgpp") // should return "w"

Find the common elements given two sorted lists

Write a function that returns a list of common elements between two sorted lists.

Example:

commonElements([]int{1, 2, 3}, []int{2, 3, 4}) // should return []int{2, 3}

Most frequently occuing element in a list

Find the most frequently occuring element in a given list.

For example, the most frequent element in [1, 2, 3, 1] is 1.

Assume a single unique element that appears more than once. In other words, you won't be given something like [1, 1, 2, 2].

Problem Set

@jboursiquot
jboursiquot / README.MD
Last active December 5, 2018 13:57
Jump into Go @ Baltimore Go User Group Meetup

Jump into Go @ Baltimore Go User Group

In this exercise your task is to work with the newline-delimited string below and count the occurrence of each character per line. You will need to make use of several features of of the Go programming language to accomplish this task, including variables, values, for and range, slices, maps, functions and reading from a file.

Success Criteria

  • Read the list of Go proverbs from proverbs.txt and handle potential errors.
  • Iterate through every proverb and count the number of times the character appears in that sentence.
  • Make use of the standard library packages only.
  • Your output should look like the sample below (though the sequence of characters will be different).
@jboursiquot
jboursiquot / challenge1-main.go
Last active December 4, 2018 17:14
GoBridge Baltimore Workshop Challenge Solutions
// Challenge 1
package main
import (
"fmt"
"strings"
)
const proverbs = `Don't communicate by sharing memory, share memory by communicating.
Concurrency is not parallelism.
@jboursiquot
jboursiquot / gist:09c9621b96ffbd84f9ef5fd83875bff0
Created February 16, 2017 15:21
git - show all commits and their tags
git log --max-count 20 --pretty=oneline --abbrev-commit --decorate
@jboursiquot
jboursiquot / sig.sh
Created February 9, 2017 18:58
Send signal to container within host
PID=$(docker inspect --format {{.State.Pid}} e885eb3b7a12)
nsenter --target $PID --mount --uts --ipc --net --pid kill -SIGQUIT 1
@jboursiquot
jboursiquot / dumptransport.go
Created January 17, 2017 13:52
Dump transport will dump Go HTTP request/response for debugging
package dumptransport
import (
"fmt"
"net/http"
"net/http/httputil"
)
type DumpTransport struct {
r http.RoundTripper