Codility Passing Car Problem in Java

This is the Java Program to Solve the passing Car Codility Problem. Problem Description Given a boolean array of 0’s and 1’s, where 0’s represent cars going to east and 1’s represent cars going to the west. Find out the pairs of the cars that will cross each other, that is, the pairs of cars … Read more

advertisement

Dutch National Flag Problem in Java

This is the Java Program to Solve the Dutch National Flag Problem. Problem Description Given an array of 0’s, 1’s and 2’s, all the elements in the random order, sort the array in linear time, without using extra space. This is known as the Dutch National Flag problem. Example: Array = [1 0 2 2 … Read more

advertisement

Java Program to Replace Elements with Greatest Element on Right Side

This is the Java Program to Replace the Element with its Next Greatest Element, Rightmost Element will be Replaced by 0. Problem Description Given an array of integers, replace each element of the array with the greatest element present on the right side of the element, in the array. The rightmost element or the last … Read more

advertisement

Java Program to Find the Smallest Positive Number Missing from an Unsorted Array

This is the Java Program to Find the Smallest Positive Integer Missing in an Unsorted Integer Array. Problem Description Given an array of integers, find out the smallest positive integer missing from the array. Example: Array = [-1, -3, 3, 2, 8 ,6] Output: 1. Problem Solution First sort the array. Then initialize a variable … Read more

advertisement

Java Program to Find the Number Occurring Odd Number of Times

This is the Java Program to Print Elements Which Occur Odd Number of Times. Problem Description Given an array of integers, print all the elements whose frequency are odd. Example: Array = [5, 4, 4, 2, 1] Output: 5 2 1. Problem Solution Iterate through the array, and for every element, count its frequency in … Read more

advertisement

Java Program to Cyclically Permute the Elements of an Array

This is the Java Program to Cyclically Permute the Elements of an Array. Problem Description Given an array of integers, cyclically permute its elements, that is, shift each array element to the left by one index. The first value will go into the last index. Example: Array: [1,2,3,4,5] Output: [2,3,4,5,1] Problem Solution Store the first … Read more

advertisement

Java Program to Find the Frequency of All Duplicate Elements in an Array

This is the Java Program to Find Repeated Elements and the Frequency of Repetition. Problem Description Given an array of integers, find and print the repeated elements and their frequency of repetition. Example: Array: [1,2,3,4,5,5,3] Output: Element—–>Frequency 3—–>2 5—–>2 Problem Solution Sort the array, and find the frequency of each repeated element and print it. … Read more

advertisement

Java Program to Find the Address of an Array

This is the Java Program to Find Address of an Array Element Given the Base Address. Problem Description Given the base address of an array, and the element size. Find out the address of the given element. Example: Base address = 2400 Element Size = 5 Element index = 6 Output: Element address = 2430 … Read more

advertisement

Java Program to Find the Number Occurring Even Number of Times

This is the Java Program to Print Elements Which Occurs Even Number of Times. Problem Description Given an array of elements, print the elements whose frequency is even. Example: array = {5, 5, 2, 2, 2, 4, 4, 1, 7, 1} Output = 5 4 1 Problem Solution Create a separate array of boolean values … Read more

advertisement

Java Program to Find Pythagorean Triplets in an Array

This is the Java Program to Check if There are Any Pythagorean Triplets in the Array. Problem Description Given an array of integers, check for any triplet of elements say a, b, and c where all three elements form a Pythagorean triplet, that is, c2 = a2 + b2 Example: Array = [1, 3, 4, … Read more

advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.