This file contains hidden or 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
// Use 'aws-sdk' and 'pg' as strings in require | |
const AWS = require('aws-sdk'); | |
const { Client } = require('pg'); | |
exports.handler = async (event) => { | |
// Use comma to separate arguments in console.log | |
console.log('Lambda event:', JSON.stringify(event)); | |
const secretName = process.env.SECRET_NAME; | |
const dbHost = process.env.DB_HOST; |
This file contains hidden or 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
from collections import deque | |
def min_weeks_to_serve(n, k, m, customers, requests): | |
requests_queue = deque(requests) | |
last_served = {customer: -float('inf') for customer in customers} # Initialize to a very early week | |
current_week = 0 | |
while requests_queue: | |
current_week += 1 | |
customer = requests_queue.popleft() |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
using namespace std; | |
int main() { | |
int n, m; | |
cin >> n >> m; | |
// Initialize familiarity matrix, true means they are familiar | |
vector<vector<bool>> familiar(n + 1, vector<bool>(n + 1, true)); |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
using namespace std; | |
int main() { | |
int n, m; | |
cin >> n >> m; | |
// Initialize familiarity matrix, true means they are familiar | |
vector<vector<bool>> familiar(n + 1, vector<bool>(n + 1, true)); |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
using namespace std; | |
int minCoupons(vector<int>& a) { | |
int n = a.size(); | |
int coupons = 0; | |
int prev = a[0]; |
This file contains hidden or 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 count_efficient_segments(n, m, pairs): | |
not_collaborated = set() | |
for x, y in pairs: | |
if x > y: | |
x, y = y, x | |
not_collaborated.add((x, y)) | |
count = 0 | |
start = 1 | |
for end in range(1, n + 1): |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#include <unordered_map> | |
#include <string> | |
using namespace std; | |
int main() { | |
int n, k, m; | |
cin >> n >> k >> m; |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#include <algorithm> | |
using namespace std; | |
int min_coupons(vector<int>& arr) { | |
int n = arr.size(); | |
vector<int> dp(n, 1); |
This file contains hidden or 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 max_subarray_cost(arr): | |
if not arr: | |
return 0 | |
max_sum = arr[0] | |
current_sum = arr[0] | |
for num in arr[1:]: | |
current_sum = max(num, current_sum + num) | |
max_sum = max(max_sum, current_sum) |
This file contains hidden or 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 <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <unordered_map> | |
using namespace std; | |
void dfs(int node, vector<int>& edges, vector<bool>& visited, vector<int>& stack, int path_sum, unordered_map<int, int>& node_to_sum, int& max_cycle_sum) { | |
visited[node] = true; | |
stack[node] = path_sum; |
NewerOlder