This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_triplets(arr, to_sum): | |
# Array length. | |
n = len(arr) | |
# Iterate through the array twice [O(n^2)] and check if the remainder of the sum is present in the dict. | |
# This helps bring the algorithm from O(n^3) to O(n^2). | |
ans = [] | |
for i in range(n - 2): | |
pseudo_sums = dict() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
// Initialize helper data structures and visited array. | |
vector<int> x{-1, 1, 0, 0}; | |
vector<int> y{0, 0, -1, 1}; | |
int visited[1000][1000] = {0}; | |
// If its a visited node, then ignore. | |
// If the element is 0 then ignore as there is no island on that path, i.e. the coast. |