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 / Java Contains Sum.java
Created October 17, 2017 05:56
Java - Checks if the number is a sum of any of the 2 numbers in the list
import java.util.Arrays;
public class App {
public static void main( String[] args ) {
int[] inArray = {1, 3, 3, 5, 7};
int baseNum = 6;
System.out.println("Number List: " + Arrays.toString(inArray) );
@jsbonso
jsbonso / Reverse a List.java
Last active December 16, 2017 17:18
Reverse a List in Java
/**
* Reverses a given List
* using Collections.reverse() method
* @param list
* @author Jon Bonso
*/
public static void reverse(List<?> list) {
Collections.reverse(list);
}
@jsbonso
jsbonso / Java Anagram Check.java
Created October 14, 2017 08:20
Java - Check if 2 strings are an Anagram of each other
/**
* Check if the two strings are an anagram of each other.
* For example: LISTEN is an Anagram of SILENT.
*
* Two strings are an anagram of each other if the characters
* and the numbers of characters that are composing them,
* are exactly the same. So for example, SUE and USE are anagrams
* because both words have one E, one S and one U,
* hence: ESU = ESU.
@jsbonso
jsbonso / Java Fibonacci Sequence.java
Last active December 16, 2017 17:20
Java Fibonacci Sequence
/**
* Calculates the next fibonacci sequence.
*
* To properly implement a Fibonacci sequence,
* we need to know the Mathematical formula first, and that is:
*
* F<sub>n</sub> = F<sub>n-1</sub> + F<sub>n-2</sub>
*
* The above formula basically reads as this:
* The next sequence (Fn) is the sum of the
@jsbonso
jsbonso / hi.js
Created April 8, 2018 05:11
Hello World NodeJS
// Import HTTP Module
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
// Create Server
const server = http.createServer((request, response) => {
@jsbonso
jsbonso / gist:cf52cf28588c53f2c269a265ecf4e184
Created May 15, 2018 13:46
Compilation of Various Core Java Questions
1. Will two objects with the same hashcode always be equal to each other?
A. Yes
B. No
C. Only when using inheritance
D. Two objects can never have the same hashcode
2. What does it mean to declare a private method as final?
A. It can only be called once.
B. It is called upon garbage collection
C. A subclass cannot override it
@jsbonso
jsbonso / gist:6d907ebfdd6915459487839b5f72ad79
Created May 23, 2018 11:27
JavaScript and CSS Reviewer
1. What's the difference between a DIV and SPAN?
- Span is in-line level and div is block level.
2. How to include the padding and border in an element's total width and height in CSS?
- Use Box Sizing: https://www.w3schools.com/css/css3_box-sizing.asp
3. How to create 2 equal DIVs?
4. How to change the second <li> of the list to red color?
@jsbonso
jsbonso / Get1stAndLastOccurenceOfANumberInAnArray.java
Created June 3, 2018 22:04
Get 1st and Last Occurence of an element in an Array
String nums = "1 2 3 3 3 3 4 5 6 7 8 9 10";
int target = 3;
String[] numsArray = nums.split(" ");
int firstIndex = 0;
int lastIndex = 0;
boolean firstIndexDone = false;
@jsbonso
jsbonso / custombinarysearch.java
Created June 3, 2018 22:05
Linear Search vs Binary Search Example (Based on time processing)
import java.util.Arrays;
public class BinarySearch {
/**
* Implementation of a Binary Search Returns -1 if no match found
*
* @param sortedArray
* @param target
Write a method that finds k-th most common element in a list. For example, kthMostCommon(new in[]{5, 4, 3, 2, 1, 5, 4, 3, 2, 5, 4, 3, 5, 4, 5},2) should return 4. In the array, element 1 occurs once, 2 twice, 3 three times, 4 fours times, and 5 five times, making element 5 the most common element in the list and 4th the second most common element,