Skip to content

Instantly share code, notes, and snippets.

View andrei14vl's full-sized avatar

Andrei Vacaroiu andrei14vl

View GitHub Profile
@andrei14vl
andrei14vl / tmux.conf
Created May 4, 2018 14:09 — forked from spicycode/tmux.conf
The best and greatest tmux.conf ever
# 0 is too far from ` ;)
set -g base-index 1
# Automatically set window title
set-window-option -g automatic-rename on
set-option -g set-titles on
#set -g default-terminal screen-256color
set -g status-keys vi
set -g history-limit 10000
#include <iostream>
#include <algorithm>
using namespace std;
struct MyType {
int val;
int extra;
} arr[100];
bool cmp(int val, MyType my_object) {
The "Quad Combination" Problem
Given an array of numbers arr and a number S, find 4 different numbers in arr that sum up to S.
Write a function that gets arr and S and returns an array with 4 indices of such numbers in arr, or null if no such combination exists.
Explain and code the most efficient solution possible, and analyze its runtime and space complexity.
Solution
The naive solution is to iterate on every possible combination of 4 numbers from arr until the required combination if found. Using 4 nested loop involves O(n4) time complexity and O(1) space complexity. This is quite inefficient.