Skip to content

Instantly share code, notes, and snippets.

@theredpea
theredpea / code_challenge_reduction_question.md
Last active October 27, 2023 18:37
code_challenge_reduction_question

Here's a code challenge I got. (I could not solve the challenge, I ran out of time. I rephrased the challenge language and I am trying the challenge again for personal growth & computer science knowledge)

Consider an array A of N integers. You can delete zero or more of its elements.

Then take the remaining elements and reduce to an integer S according to these rules:

  • elements in even positions are added
  • elements in odd positions are subtracted: e.g. S = A[0] − A[1] + A[2] − A[3] + ...
@theredpea
theredpea / equilateral-triangles-overlap-area.ipynb
Created October 25, 2023 00:37
Equilateral Triangles Overlap Area.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@theredpea
theredpea / code_challenges_cf.js
Last active October 27, 2023 18:23
Code Challenges
/*
Write a function solution that, given a string S consisting of N letters 'a' and/or 'b' returns true when all occurrences of letter 'a' are before all occurrences of letter 'b' and returns false otherwise.
Examples:
1. Given S = "aabbb", the function should return true.
2. Given S = "ba", the function should return false.
3. Given S = "aaa", the function should return true. Note that 'b' does not need to occur in S.
using System;
using System.Collections.Generic;
using System.Linq;
// Online C# Editor for free
// Write, Edit and Run your C# code using C# Online Compiler
class Solution {
// TODO: maybe dont need to store class/object TradingEvent
public class TradingEvent {
@theredpea
theredpea / embolden_substrings_tech_challenge.js
Created October 12, 2023 23:07
Technical Challenge Interview
/******************/
/**** Solution ****/
/******************/
function emboldenSubstrings(input, substrings) {
// Implement me!
// if (!substrings.length) {
// return input;
// }

Steps to reproduce

  1. Using Windows 10 laptop, following instructions here, run docker run -d -p 80:80 owncloud
  2. Open owncloud on localhost:80 , setup the admin username and password, navigate to marketplace

Expected behaviour

Can reach marketplace

Actual behaviour

Marketplace throws error:

['2014', '2015','2016','2017','2018','2019','2020','2021','2022'].map(year=>{ return ['01','02','03','04', '05','06','07','08','09','10','11','12'].map(month=>[year, month]);}).flat()
.forEach(async ([year, month])=>{
let fetch_url = `https://www.mybenefitwallet.com/BW/activities/eStatement?year=${year}&month=${month}`;
// https://stackoverflow.com/a/24586168/1175496
await fetch(fetch_url)
.then(response => response.blob())
.then(blob => {
var url = window.URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = url;
alert(`Hello Nate! Hope today's Beerfest was a success. So Elizabeth Johnson had signed up for a monthly membership but was double billed for both June and July for a total of $70. Can we reimburse her? Her Venmo account is @E.Johnson-2496. Thanks. Can you verify that she has cancelled her monthly membership? She now would like to pay month to month.`);
// club.spond.com
///=============================
///=============================
///=============================
///=============================
const squid_spond_clubid = "39004B1375F244F4AFECC14513031501"
const fetch_opts = {
"credentials": "include",
"mode": "cors",
// club.spond.com
///=============================
///=============================
///=============================
///=============================
const squid_spond_clubid = "39004B1375F244F4AFECC14513031501"
const fetch_opts = {
"credentials": "include",
"mode": "cors",
};
function JSONToCSVConvertor(JSONData, ReportTitle, ShowLabel, appendString) {
//If JSONData is not an object then JSON.parse will parse the JSON string in an Object
var arrData = typeof JSONData != 'object' ? JSON.parse(JSONData) : JSONData;
var CSV = '';
//This condition will generate the Label/Header
if (ShowLabel) {
var row = "";
//This loop will extract the label from 1st index of on array