Skip to content

Instantly share code, notes, and snippets.

View Se7soz's full-sized avatar

Hussein Elsayed Se7soz

View GitHub Profile
/**
* Update1: The solution didn't handle cases when a node covers its neighbours too
* Update2: Tested with randomly generated test cases ~10K
* Update3: Add an optimization to limit the max strength to range from -W to W, where W is the tree width
* DISCLAIMER:
* This solution is written for explanation/educational purposes
* and its intended to not follow coding guidelines or best practices
* as the main intention is to explain the thinking strategy in a way
* that's a little bit better than writing pseudo-code and to allow
* student(s) to test and add debugging messages in every step.
struct TrieNode {
public:
void insert(const string& word, int i) {
if (i >= word.size()) {
return;
}
if (children[word[i]] == NULL) {
children[word[i]] = new TrieNode();
class Solution {
public:
vector<string> wordBreak(string s, vector<string>& wordDict) {
root = new TrieNode();
for (string word : wordDict) {
root->insert(word, 0);
}
return wordBreakHelper(s, 0);
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<functional>
using namespace std;
class Comparator {
public:
bool operator () (const pair<int, function<void()>> p1, const pair<int, function<void()>> p2) {
@Se7soz
Se7soz / Word-Break-2-se7so.cpp
Created May 28, 2020 12:59
Word Break II solution
struct TrieNode {
public:
void insert(const string& word, int i) {
if (i >= word.size()) {
return;
}
if (children[word[i]] == NULL) {
children[word[i]] = new TrieNode();
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#include<cstring>
#include<queue>
#include<map>
#include<stack>
#include<climits>
import lombok.SneakyThrows;
import lombok.extern.log4j.Log4j2;
import org.apache.logging.log4j.Level;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
@Log4j2
public class Example {
@SneakyThrows
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>selenium-example</groupId>
<artifactId>automation-test</artifactId>
<version>1.0-SNAPSHOT</version>
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import java.util.Arrays;
import java.util.List;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CSVLineParser {
private CSVLineReader reader;
public CSVLineParser(CSVLineReader reader) {
this.reader = reader;
}