Tag: java

  • Classes in Javascript vs Java

    Nothing happens outside a class in Java. To create an object you need a class. Even to print a simple “Hello World” you need a class. That is not always the case with Javascript. You can create objects without using a class. Everything need not be encapsulated within a class! There are similarities between the…

  • Variables – Java vs Javascript

    Variables are critical to any programming language. It is where you store temporary data. Not all data needs to be stored in the database, whatever doesn’t need to be stored in the database and is needed temporarily during your program execution are stored in variables. Variables in Javascript differ from variables in Java in quite…

  • Java vs Javascript – Say Hello World!

    One of the complaints about Java programming language is that it is verbose. Imagine you are new to programming. And you want to learn to program. The first thing most of us traditionally do is to print “Hello World!” . And to do this in Java you need to go through a lot of ordeal:…

  • try catch block in Java vs Javascript

    In both Java and JavaScript, the try-catch block is used to handle exceptions that may occur in the code. The basic structure of a try-catch block in both languages is similar: a block of code is put in a “try” block, and any exceptions that are thrown in that block are caught and handled in…

  • Median of Two Sorted Arrays

    Problem : Given two sorted arrays find the median of the sorted arrays when merged. Find a solution in less than O(n) time complexity where n is the length of the merged array. Also don’t use extra space – Space complexity should be O(1) What is median? Median is the middlemost element of a sorted…

  • Delete Node in a Linked List given only the node

    Problem: You are given a node to delete from a linked list. But you are not given the head node. Delete it in O(1) time and O(1) space complexity. Constraints: For example, Given the linked list : 1 -> 4 -> 7 -> 8 And the node 7 to be deleted The output should be…

  • Course Schedule II

    Problem : Given an integer array representing prerequisites of different courses and the total number of courses , find out the order in which the courses should be taken. For example, if the given input is [1,0] It means to take course 1 you should have completed course 0. Or in other words, Course 0…

  • Odd Even Linked List

    Problem: Given the head of a linked list , reorder the linked list so that the elements in odd indices are grouped together followed by the elements in event indices. The first index is assumed to be 1 (odd) and the second index even and so on. For example, For the below input: 1 ->…

  • Find first and last position of element in sorted array

    Problem: Given a sorted integer array find the first and last position of given target element For example, If given array is [ 1,3,6,6,7,9] and target is 6 Then output is [2,3] which represents the first and last index position of the element 6 For the same input if the target is 8 Then the…

  • Find the next highest permutation of an array

    Problem: Given an integer array , find the next highest permutation of the numbers. If the next highest permutation is not found return the smallest permutation of the given input. Permutation of a number is all possible combinations of the given numbers. For example, Given the array: [1,2,3] The possible permutations are [1,3,2] , [2,1,3],…