Oracle Interview Question for Senior Software Development Engineers


Country: India
Interview Type: In-Person




Comment hidden because of low score. Click to expand.
0
of 0 vote

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			String str = reader.readLine();
			Long num = Long.parseLong(str);
			Long digit = 0L;
			Map<Long, Integer> countmap = new LinkedHashMap<Long, Integer>();
			List<Long> numList = new LinkedList<Long>();
			Boolean magicFlag = false;
			while (num > 0) {
				digit = num % 10;
				num = num / 10;
				numList.add(digit);
				if (countmap.containsKey(digit)) {
					int val = countmap.get(digit);
					countmap.put(digit, val + 1);
				} else {
					countmap.put(digit, 1);
				}
			}
			System.out.println(countmap);
			System.out.println(numList);
			int thriceCount = 0;
			if (numList.contains(1L) && numList.contains(2L) && numList.contains(3L) && numList.contains(4L)
					&& numList.contains(5L) && numList.contains(6L)) {
				magicFlag = true;
			}
			long prev = -1;
			long current = -1;
			long diff1 = 0;
			long diff2 = 0;
			long next = -1;
			if (!magicFlag) {
				for (Long n : numList) {
					if (prev == -1) {
						prev = n;
					} else if (current == -1) {
						current = n;
					} else {
						next = n;
					}
					if (prev != -1 && current != -1 && next != -1) {
						diff1 = Math.abs(current - prev);
						diff2 = Math.abs(next - current);
						if (diff1 == 1 && diff2 == 1) {
							magicFlag = true;
							break;
						}
						prev = current;
						current = next;
					}
				}
			}
			if (!magicFlag) {
				for (Map.Entry<Long, Integer> e : countmap.entrySet()) {

					if (e.getValue() >= 3) {
						thriceCount++;
					}
					if (thriceCount >= 3) {
						magicFlag = true;
						break;
					}
				}
			}
			if (magicFlag == true) {
				System.out.println("Magic Flag");
			} else {
				System.out.println("Not a magic Flag");
			}

- Anonymous February 26, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

import java.util.List;
import java.util.ArrayList;
import java.util.Set;
import java.util.HashSet;
import java.lang.Math;
class MagicNumber{
	public static void main(String[] args){
		long n=9876542361L;
		// long n=9786534210L;
		// long n=9786533450L;
		// long n=9786533222L;
		// long n=9988776655L;
		List<Integer> consecutives = new ArrayList<>();
		Set<Integer> sixDigits = new HashSet<>();
		int[] digitsCount = {0,0,0,0,0,0,0,0,0,0};
		int d;
		boolean isMagicFlag = false;
		while(n>0){
			d=(int)Math.abs(n%10);
			// System.out.println(d);

// checking consecutiveness
			if(0==consecutives.size())
				consecutives.add(d);
			else if(1==consecutives.size()){
				if(1==d-consecutives.get(0) || -1==d-consecutives.get(0))
					consecutives.add(d);
				else{
					consecutives.remove(0);
					consecutives.add(d);
				}
			}
			else{
				if(d-consecutives.get(1) == consecutives.get(1)-consecutives.get(0)){
					System.out.println("it is a magic number - consecutive");
					isMagicFlag =  true;
					break;
				}
				else{
					consecutives.remove(1);
					consecutives.remove(0);
					consecutives.add(d);
				}
			}
// checking first 6 digits present
			if(6>=d)
				sixDigits.add(d);
			if(6==sixDigits.size()){
				System.out.println("it is a magic number - first 6 digits present");
				isMagicFlag =  true;
				break;
			}
// checking 3 occurence of any digit
			if(2==digitsCount[d]){
				System.out.println("it is a magic number - occure 3 times");
				isMagicFlag =  true;
				break;
			}
			else{
				++digitsCount[d];
			}

			n/=10;
		}

		if(!isMagicFlag) System.out.println("this is not a magic number");
	}

}

- Simon March 27, 2019 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

private static boolean checkMagicNumber(long number) {
		boolean isNumberBwOneToSix = true;
		boolean isNumberBwZeroToNine = false;
		boolean isConsicutive = false;
		boolean isMagicNumber = false;
		boolean consicutiveInOrDe = false;
		long prevNumber = 0;
		int consicutiveBwNine = 0;
		int consicutiveInOrDeCount = 0;

		while(number > 0) {
			long reminder = number % 10;
			number = number / 10;
			if(isNumberBwOneToSix && (reminder < 1 || reminder > 6)) {
				isNumberBwOneToSix = false;
			}
			if(reminder >= 0 && reminder <= 9) {
				consicutiveBwNine++;
			}
			if(consicutiveBwNine == 3) {
				isConsicutive = true;
				return isConsicutive;
			}
			if(prevNumber == 0) {
				prevNumber = reminder;
				consicutiveInOrDeCount++;
			}else if(prevNumber + 1 == reminder) {
				consicutiveInOrDeCount++;
			}else if(prevNumber - 1 == reminder) {
				consicutiveInOrDeCount++;
			}else {
				consicutiveInOrDeCount = 1;
			}
			prevNumber = reminder;
			if(consicutiveInOrDeCount == 3) {
				consicutiveInOrDe = true;
				return consicutiveInOrDe;
			}
			if(isNumberBwOneToSix || isConsicutive || consicutiveInOrDe) {
				isMagicNumber = true;
			}
		}
		return isMagicNumber;

}

- Rangan Roy September 08, 2020 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More