163 subscribers
3.42K photos
24 videos
39 files
371 links
Link: @java_posts

Contact: java.response.email@gmail.com
Download Telegram
Pattern 8
#Source_code
#43
Pattern 9
#Source_code
#44
Media is too big
VIEW IN TELEGRAM
Java Modules in Real Life
Get advice on why, when, when not,and how to use Java modules in real life for your Java projects.
Pattern 10
#Source_code
#45
Pattern 11
#Source_code
#46
Find the Duplicate element in a limited range array
Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space.

#Data_structure
Java
Find the Duplicate element in a limited range array Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space. #Data_structure
Using Hashing
The idea is to use hashing to solve this problem. We can use a visited boolean array to mark if an element is seen before or not. If the element is already encountered before, the visited array will return true.
#Data_structure
#Source_code
Java
Find the Duplicate element in a limited range array Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space. #Data_structure
Using Array Indices
We can solve this problem in constant space. Since the array contains all distinct elements except one and all elements lie in range 1 to n-1, we can check for a duplicate element by marking array elements as negative using the array index as a key. For each array element nums[i], invert the sign of the element present at index nums[i]. Finally, traverse the array once again, and if a positive number is found at index i, then the duplicate element is i.

The above approach takes two traversals of the array. We can achieve the same in only a single traversal. For each array element nums[i], invert the sign of the element present at index nums[i] if it is positive; otherwise, if the element is already negative, then it is a duplicate.

#Data_structure
#Source_code
Media is too big
VIEW IN TELEGRAM
Project Panama: Interconnecting the Java Virtual Machine and Native Code

Project Panama improves and enriches the connections between the Java Virtual Machine (JVM) and non-Java APIs, including many interfaces commonly used by C programmers. This session will offer an overview and demo of features from Project Panama, including JDK Enhancement Proposal (JEP) 434 from Java 20.
Java
Find the Duplicate element in a limited range array Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space. #Data_structure
Using XOR
We can also solve this problem by taking xor of all array elements with numbers 1 to n-1. Since the same elements will cancel each other as a^a = 0, 0^0 = 0 and a^0 = a, we will be left with the duplicate element.
Java
Find the Duplicate element in a limited range array Given a limited range array of size n containing elements between 1 and n-1 with one element repeating, find the duplicate number in it without using any extra space. #Data_structure
Using Difference in Sum
Finally, the post is incomplete without this textbook solution: find the sum of all element and find the difference between it and all elements which are supposed to be there
Pattern 12
#Source_code
#47