Skip to content

Instantly share code, notes, and snippets.

View vignarajj's full-sized avatar
🎯
Focusing

vignaraj R.R. vignarajj

🎯
Focusing
View GitHub Profile
@vignarajj
vignarajj / FibonacciExample.Java
Last active January 21, 2019 07:50
To find the next Fibonacci number - Java
import java.util.HashMap;
import java.util.Map;
public class FibonacciExample {
//Check the number is perfect square or not.
static boolean isPerfectSquare(int x) {
int s = (int) Math.sqrt(x);
return (s * s == x);
@vignarajj
vignarajj / SubsetExample.Java
Created January 18, 2019 11:33
Write a function that takes two arrays as input, each array contains a list of A-Z;
import java.util.Arrays;
import java.util.HashSet;
public class SubsetExample {
public static boolean isSubset_simple(String arr1[],String arr2[]) {
int i = 0;
int j = 0;
int m = arr1.length;
int n = arr2.length;
@vignarajj
vignarajj / answers.md
Last active January 21, 2019 08:16
Oursky Developer Pre-Test

Question: 1 Write a function that takes two arrays as input, each array contains a list of A-Z; Your program should return True if the 2nd array is a subset of 1st array, or False if not.

Answer:

 import java.util.Arrays;
 import java.util.HashSet;
@vignarajj
vignarajj / NonRepeatCharacters.Java
Created January 21, 2019 08:03
To Generate the non-repeated characters of String. Given two integers X and Y, returns containing exactly X letters "A" and exactly Y letters "b". X defines maximum of character repetition.
public class NonRepeatCharacters {
public static void main(String[] args) {
System.out.println("Answer is " + NonRepeatString(2, 5, 3));
}
// n = Maximum number of repeation;
// x = 1st character with number of times.
// y -2nd character with number of times.
public static String NonRepeatString(int n, int X, int Y) {
String biggerString, smallerString;
@vignarajj
vignarajj / TrainComposition.Java
Created January 29, 2019 08:01
TrainComposition Solution in Java.
package javaproblems;
import java.util.Deque;
import java.util.LinkedList;
public class TrainComposition {
private final Deque<Integer> wagons = new LinkedList<>();
public void attachWagonFromLeft(int wagonId) {
@vignarajj
vignarajj / Folders.Java
Created January 29, 2019 08:07
Implement a function FolderNames, which accepts a string containing an XML file that specifies folder structure and returns all folder names that start with startingLetter.
package javaproblems;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collection;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
@vignarajj
vignarajj / PrintDiffChar.Java
Created January 29, 2019 08:10
Print the characters in String not repeated.
package javaproblems;
import java.util.Scanner;
public class PrintDiffChar {
public static void main(String[] args) {
String text;
int count;
char ch;
@vignarajj
vignarajj / CaptializeChar.Java
Created January 29, 2019 08:12
Capitalize First and Last character of String
package javaproblems;
public class CaptializeChar {
public static String getCaptilizeString(String words){
if(words.length()<=0){
return "Invalid String";
}
String[] splitWords = words.split("\\ ");
@vignarajj
vignarajj / MaximumProduct.Java
Last active February 13, 2019 04:28
Find the maximum products of any 2 numbers in the array
package javaproblems;
public class MaximumProduct {
public static void main(String[] args){
int[] arr = {1,2,-3,4,5};
getMaximumNumbers(arr);
}
public static void getMaximumNumbers(int[] arr){
int len = arr.length;
@vignarajj
vignarajj / MostAppear.Java
Created February 13, 2019 04:29
Find the integer appearing most time in the array
public class MostAppear {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 1, 6, 1, 2, 2, 2, 2, 4, 6};
System.out.println("Max appearance number is " + maxAppearance(arr));
}
public static int maxAppearance(int[] arr) {
int len = arr.length;
int max_count = 1;