🌐
GitHub
github.com › jgomez-m › HackerRank › blob › master › src › hacker › rank › java › threads › transactions › Solution.java
HackerRank/src/hacker/rank/java/threads/transactions/Solution.java at master · jgomez-m/HackerRank
public class Solution { private static final Scanner SCANNER = new Scanner(System.in); private static final Account ACCOUNT = new Account(); private static final Transaction TRANSACTION = new Transaction(ACCOUNT); · public static void main(String[] args) throws InterruptedException { int threadsCount = Integer.parseInt(SCANNER.nextLine()); Thread[] threads = new Thread[threadsCount]; ·
Author   jgomez-m
🌐
Reddit
reddit.com › r/leetcode › need help with a question i came across recently in a test
r/leetcode on Reddit: Need help with a question I came across recently in a test
October 16, 2023 -

I was able to come up with a graph traversal solution but couldn't get all the test cases.

Question:

There are service_nodes of different micro-services in a system with bidirectional connections in the form of a tree (acyclic graph), where the ith edge connects the micro-services service_from[i] and service_to[i]. Each micro-service is configured with a maximum number of live threads that can be present in its lifecycle, where the ith micro-service can have a maximum of threads[i] threads. The micro-services adjacent to each other must have maximum threads differing by exactly 1.

Some configurations were lost, and only k of the micro-services are known. This information is given as a 2D array, currentValues, of size k x 2 denoting [micro-service index, maximum threads], or, [i, threads[i]]

Find the maximum number of live threads that each micro-service can have such that the total number of live threads in the system is the minimum possible. Return an array of length service nodes where the element denotes the maximum number of live threads for the micro-service.

Note: It is guaranteed that the solution always exists.

Constraints 1 <= node_count <= 105 number of given values for nodes <= node_count 1 <= value of a node <= 105

Example

given graph => (1:3)-(2:x)-(3:x)-(4:x)-(5:3) node 1 to 5 (given) for nodes 1 and 5, we have been given the max thread value as 3 and 3, respectively we need to find all x values such that max sum is minimum and adjacent nodes differ by 1 solution for the above graph => (1:3)-(2:2)-(3:1)-(4:2)-(5:3) so we return [3,2,1,2,3]

Discussions

java - Static Thread Analysis: Good idea? - Stack Overflow
I help maintain and build on a fairly large Swing GUI, with a lot of complex interaction. Often I find myself fixing bugs that are the result of things getting into odd states due to some race con... More on stackoverflow.com
🌐 stackoverflow.com
Hackerrank solutions: Python 3 and Perl 6 (part 1)
For Simple Array Sum solution in python3: simpleArraySum = sum And done ;-) More on reddit.com
🌐 r/Python
7
2
September 13, 2018
Hackerrank Top Earners Problem
A few things: The problem is asking for you to show the maximum total earnings, so you will need to include it in your select statement --> SELECT (salary * months) AS total_earnings Since they want the number of employees making the max amount, you will need to aggregate by total earnings. Once you do the first two, you can find the max by ordering by earnings in descending order and taking the top value. This leaves you with: SELECT (salary * months) AS total_earnings, COUNT(*) FROM employee GROUP BY total_earnings ORDER BY total_earnings DESC LIMIT 1; More on reddit.com
🌐 r/learnSQL
8
5
August 10, 2021
HackerRank - Array Pairs Problem Help
Note that you don't need to print the actual pairs - you can alter the array to optimize. You should be able to find the maximum element of the array in a single pass (O(n)). Then, for each element, you want to check with how many elements after it it would give a product of less than or equal that amount with. However, looking through all cases would result in O(n2) complexity, which is just slightly too much. Now, consider you reorder the array such that the smaller elements are at the front and the larger ones at the end - now, you can find the largest number such that when multiplied by the current one, it yields a number less than or equal to the maximum (note that a special case is needed for 0). If you reordered the array, you could then search for the position up to which all the elements are less than or equal to the maximum factor (using binary search) - that would be O(log n) per element or O(n log n) in total, which should fit nicely in the given bounds. (All the elements before that position should give a product less than or equal to the maximum, while all the ones after should give a product larger than the maximum). More on reddit.com
🌐 r/learnprogramming
3
1
March 11, 2020
🌐
Medium
medium.com › @ByteCodeBlogger › ubs-java-developer-hackerrank-mcq-on-concurrent-threads-9407965cf4b5
UBS java Developer — Hackerrank MCQ on Concurrent Threads - Full Stack Developer - Medium
June 1, 2024 - UBS java Developer — Hackerrank MCQ on Concurrent Threads Q : Five threads are accessing a shared resource. The common variable being accessed by all of them is ‘x’ and the common code being …
🌐
Medium
medium.com › @vidhyamanickaraj › java-string-concepts-with-example-f05f77c8c5f3
Java String Concepts With Example HackerRank String Questions With Solutions | by vidhya manickaraj | Medium
April 17, 2024 - By default, Stringbuffer is Synchronized, which means at one time,only one thread will get executed.(Thread means some piece of logic/code/functionality).
🌐
HackerRank
hackerrank.com › skills-directory › java_intermediate
Java (Intermediate) | Skills Directory | HackerRank
These parts are known as threads and are lightweight processes available within the process.
🌐
YouTube
youtube.com › watch
All Leetcode Multithreading questions solved - YouTube
In this video I have discussed solutions to all multithreading questions present on leetcode.Implemented in C++17https://leetcode.com/problems/print-in-order...
Published   June 11, 2023
🌐
HackerRank
hackerrank.com › challenges › uds-echo-server › problem
UDS Echo Server | HackerRank
Your task is to write a UNIX Domain Socket(UDS) server which can accept connection from 'N' clients. Each client will send text data over the socket. Read the data and send it back to the client.
🌐
GitHub
github.com › anishLearnsToCode › hackerrank-java-basic-skill-test › blob › master › test-thread.md
hackerrank-java-basic-skill-test/test-thread.md at master · anishLearnsToCode/hackerrank-java-basic-skill-test
Contains solved programs for the HackerRank Java (Basics) Skill Test Certification 🎓. - anishLearnsToCode/hackerrank-java-basic-skill-test
Author   anishLearnsToCode
Find elsewhere
🌐
GitHub
github.com › doocs › leetcode › blob › main › solution › 1800-1899 › 1834.Single-Threaded CPU › README_EN.md
leetcode/solution/1800-1899/1834.Single-Threaded CPU/README_EN.md at main · doocs/leetcode
class Solution { public int[] getOrder(int[][] tasks) { int n = tasks.length; int[][] ts = new int[n][3]; for (int i = 0; i < n; ++i) { ts[i] = new int[] {tasks[i][0], tasks[i][1], i}; } Arrays.sort(ts, (a, b) -> a[0] - b[0]); int[] ans = new ...
Author   doocs
🌐
Quora
quora.com › Where-can-I-find-practice-problems-and-exercises-on-multi-threading-scenarios
Where can I find practice problems and exercises on multi threading scenarios? - Quora
Answer (1 of 3): The Little Book of Semaphores The above book is language and framework agnostic, it claims it covers all possible race conditions classical or otherwise in a puzzle/program format and has great reviews as well, see if you can do it end to end. also Google pthread practice exerc...
Top answer
1 of 3
8

This answer is more focused on the theory aspect of your question.

Fundamentally you are making an assertion: "This methods runs only under certain threads". This assertion isn't really different than any other assertion you might make ("The method accepts only integers less than 17 for parameter X"). Issues are

  • Where do such assertions come from?
  • Can static analyzers check them?
  • Where do you get such a static analyzer?

Mostly such assertions have to come from the software designers, as they are the only people that know the intentions. The traditional term for this is "Design by Contract", although most DBC schemes are only over the current program state (C's assert macro) and they should really be over the programs' past and future states ("temporal assertions"), e.,g., "This routine will allocate a block of storage, and eventually some piece of code will deallocate it". One can build tools that try to determine hueristically what the assertions are (e.g., Engler's assertion induction work; others have done work in this area). That's useful, but the false positives are an issue. As practical matter, asking the designers to code such assertions doesn't seem particularly onerous, and is really good long term documentation. Whether you code such assertions with a specific "Contract" language construct, or with an if statement ("if Debug && Not(assertion) Then Fail();") or hide them in an annotation is really just a matter of convenience. Its nice when the language allows to code such assertions directly.

Checking of such assertions statically is difficult. If you stick with current-state only, the static analyzer pretty much has to do full data flow analysis of your entire application, because the information needed to satisfy the assertion likely comes from data created by another part of the application. (In your case, the "inside EDT" signal has to come from analyzing the whole call graph of the application to see if there is any call-path that leads to the method from a thread which is NOT the EDT thread). If you use temporal properties, the static check pretty much needs some kind of state-space verification logic in addition; these are presently still pretty much research tools. Even with all this machinery, static analyzers generally have to be "conservative" in their anlayses; if they can't demonstrate that something is false, they pretty much have to assume it is true, because of the halting problem.

Where do you get such analyzers? Given all the machinery needed, they're hard to build and so you should expect them to be rare. If somebody has built one, great. If not... as a general rule, you don't want do this yourself from scratch. The best long-term hope is to have generic program analysis machinery available on which to build such analyzers, to amortize the cost of building all the infrastructure. (I build program analyzer tool foundations; see our DMS Software Reengineering Toolkit).

One way to make it "easier" to build such static analyzers is to restrict the cases they handle to narrow scope, e.g., CheckThread. I'd expect CheckThread to do exactly what it presently does, and it would be unlikely to get a lot stronger.

The reason that "assert" macros and other such dynamic "current state" checks are popular is that they can actually be implemented by a simple runtime test. That's pretty practical. The problem here is that you may never exercise a path that leads to a failed conditions. So, for dynamic analysis, absence of detected failure is not really evidence of correctness. Still feels good.

Bottom line: static analyzers and dynamic analyzers each have their strength.

2 of 3
3

We haven't tried any static analysis tools, but we've used AspectJ to write a simple aspect that detects at runtime when any code in java.awt or javax.swing is invoked outside the EDT. It has found several places in our code that were missing a SwingUtilities.invokeLater(). We run with this aspect enabled throughout our QA cycle, then turn it off shortly before release.

🌐
Coderank
coderank.solutions › hackerrank-solutions
All HackerRank Solutions
We’ve classified each HackerRank problem and its solution—across Python, Java, C++, SQL, and more—to help you better prepare for your next coding test.
🌐
GitHub
github.com › sonmez-hakan › hackerrank
GitHub - sonmez-hakan/hackerrank: This repository is mostly Java & PHP solutions of HackerRank Algorithms & Data Structures' Questions. However, there are some C# solutions. · GitHub
June 20, 2024 - This repository is mostly Java & PHP solutions of HackerRank Algorithms & Data Structures' Questions. However, there are some C# & Python solutions.
Starred by 37 users
Forked by 6 users
Languages   Java 50.5% | PHP 26.9% | C# 20.8% | Python 1.6% | C++ 0.2%
🌐
Coderanch
coderanch.com › t › 777054 › languages › Python-Hackerrank-code
Python Hackerrank code (Jython/Python forum at Coderanch)
Sachin Doe wrote:Provide a solution for the below question Right, hello, good day...? What have you got so far? Please post the code and someone would have a look. ... Please use the code button whenever you post code, and break up the long lines if possible. I have added code tags to your post, and doesn't it look better now ... Boost this thread!
🌐
PREP INSTA
prepinsta.com › home › hackerrank test papers and placement papers › hackerrank advanced coding questions
HackerRank Advanced Coding Questions | PrepInsta
August 8, 2025 - HackerRank Advanced Coding Questions, which have been asked in the previous years, are given here with solutions for practicing hackerrank.
🌐
HackerRank
hackerrank.com › contests › code-a-thon › challenges › concurrency-check › submissions
Programming Problems and Competitions :: HackerRank
Code your solution in our custom editor or code in your own environment and upload your solution as a file.4 of 6
🌐
HackerRank
hackerrank.com › challenges › count-solutions › problem
Count Solutions | HackerRank
For each test case, print one line, the number of pairs that are valid solutions to Eric's equation.
🌐
HackerRank
hackerrank.com
HackerRank - Online Coding Tests and Technical Interviews
HackerRank is the market-leading coding test and interview solution for hiring developers. Start hiring at the pace of innovation!
🌐
Programmingoneonone
programmingoneonone.com › home › hackerrank count strings problem solution
HackerRank Count Strings problem solution
January 23, 2026 - HackerRank Count Strings problem solution in python, java, c++, c and javascript programming with practical program code example explanation