Skip to content

Instantly share code, notes, and snippets.

View jsbonso's full-sized avatar
🎯
portal.tutorialsdojo.com

Jon Bonso jsbonso

🎯
portal.tutorialsdojo.com
View GitHub Profile
@jsbonso
jsbonso / FindTheLengthOfLongestSubstringUsingWhileLoop.java
Created October 19, 2022 10:09
Find the Length Of Longest Substring using Sliding Window Technique via a WHILE Loop
class FindTheLengthOfLongestSubstringUsingWhileLoop {
public int lengthOfLongestSubstring(String s) {
/**
Examples:
#1 -
eabcdabcbb = 4
"abcd" is the longest substring
4 is the length of "abcd"
@jsbonso
jsbonso / FindTheLengthOfLongestSubstring.java
Created October 19, 2022 10:06
Find the Length Of Longest Substring using Sliding Window Technique
class FindTheLengthOfLongestSubstring {
public int lengthOfLongestSubstring(String s) {
/**
Examples:
#1 -
eabcdabcbb = 4
"abcd" is the longest substring
4 is the length of "abcd"
@jsbonso
jsbonso / TwoSumBruteForce.java
Created October 15, 2022 08:58
Two Sum Solution #1 - Brute Force Approach
/**
*
Two Sum Solution #1 - Brute Force Approach
Approach
- Brute force approach by using a nested loop
- Create the two loops to process the array, wherein the second loop is one step ahead of the previous loop and traversing the array elements in a quadratic manner
- The first loop uses the variable i to hold the first index while the second loop uses the variable j to hold the latter one.
- Compare the values of the i and j indices. If they are the same, return the indices as output
@jsbonso
jsbonso / Palindrome.java
Created October 18, 2022 21:18
Check if a Given String is a Palindrome
public class Palindrome
{
public static void main(String[] args) {
String input = "ababa";
String input1 = "mom";
String input2 = "nono";
String input3 = "A man, a plan, a canal: Panama!";
@jsbonso
jsbonso / TwoSumMethodsPerformanceChecks.java
Last active October 18, 2022 19:46
Tracks the Elapsed Time for the 2 Solutions for the Classic Two Sum Problem
/**
This tracks the Elapsed Time for the 2 Solutions for the Classic Two Sum Problem
You will discover how immensely better an (O)n solution is (twoSumOptimized)
than a brute force (O)n^2 solution (twoSumBruteForce) by checking the start and end
times of both methods
*/
import java.util.Map;
@jsbonso
jsbonso / TwoSumUsingHashMapSinglePass.java
Last active October 18, 2022 03:29
Two Sum Solution #2 - Using a HashMap and iterates the array in a single pass approach
/**
*
Two Sum Solution #2 - Using a HashMap and iterates the array in a single pass approach
Author: Jon Bonso
Goal: Get the two indices from the array that sums up to the value of the given target
MATH THEORY:
@jsbonso
jsbonso / OddOrEven.java
Last active October 17, 2022 13:19
Simple Odd or Even Coding Example
/*
Simple Odd or Even Coding Example
Author: Jon Bonso
Demo Link: https://www.online-java.com/BYJCIjwhpg
Mathematical Theory:
- Parity is the property of an integer which determines if it is even or odd.
- An even number is an integer that can be divided exactly by 2 is an even number.
@jsbonso
jsbonso / index.html
Created June 6, 2018 19:35
Simple Checkout with Price Rules App using Vanilla JavaScript
<!DOCTYPE html>
<html>
<body>
<h1>Simple Checkout with Price Rules</h1>
<div style="padding-bottom: 25px;">
<h3>Test Case 1: 3 CARI Products</h3>
<p>SKUs Scanned: <code>cari, cari, cari, peti </code></p>
<p>Total expected: $249.00</p>
@jsbonso
jsbonso / How to connect Java to MySQL.java
Created October 23, 2017 20:57
How to connect Java to MySQL Database
package com.tutorialsdojo;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSetMetaData;
/**
@jsbonso
jsbonso / VoteCount.java
Last active September 20, 2022 11:19
Counts the number of votes for each Candidates and shows the winner
import java.util.*;
import java.util.concurrent.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
public class VoteCount{
public static void main(String[] args) {
// Populate Data
String[] votes = {"Jon", "Bonso", "Stacey", "Jon", "Bonso", "Stacey", "Jon", "Bonso", "Brie", "Jon", "Bonso", "Jon"};