Fraudulent Activity Notifications in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]

Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, Algorithm Solutions of Problem Solving Section in Java. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.

In this post, you will find the solution for Fraudulent Activity Notifications in Java-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.

Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.

Introduction To Algorithm

The word Algorithm means “a process or set of rules to be followed in calculations or other problem-solving operations”. Therefore Algorithm refers to a set of rules/instructions that step-by-step define how a work is to be executed upon in order to get the expected results. 

Advantages of Algorithms:

  • It is easy to understand.
  • Algorithm is a step-wise representation of a solution to a given problem.
  • In Algorithm the problem is broken down into smaller pieces or steps hence, it is easier for the programmer to convert it into an actual program.

Link for the ProblemFraudulent Activity Notifications – Hacker Rank Solution

Fraudulent Activity Notifications – Hacker Rank Solution


HackerLand National Bank has a simple policy for warning clients about possible fraudulent account activity. If the amount spent by a client on a particular day is greater than or equal to  the client’s median spending for a trailing number of days, they send the client a notification about potential fraud. The bank doesn’t send the client any notifications until they have at least that trailing number of prior days’ transaction data.

Given the number of trailing days  and a client’s total daily expenditures for a period of  days, determine the number of times the client will receive a notification over all  days.


On the first three days, they just collect spending data. At day , trailing expenditures are . The median is  and the day’s expenditure is . Because , there will be a notice. The next day, trailing expenditures are  and the expenditures are . This is less than  so no notice will be sent. Over the period, there was one notice sent.

Note: The median of a list of numbers can be found by first sorting the numbers ascending. If there is an odd number of values, the middle one is picked. If there is an even number of values, the median is then defined to be the average of the two middle values. (Wikipedia)

Function Description

Complete the function activityNotifications in the editor below.

activityNotifications has the following parameter(s):

  • int expenditure[n]: daily expenditures
  • int d: the lookback days for median spending


  • int: the number of notices sent

Input Format

The first line contains two space-separated integers  and , the number of days of transaction data, and the number of trailing days’ data used to calculate median spending respectively.
The second line contains  space-separated non-negative integers where each integer  denotes .


Output Format

Sample Input 0

STDIN               Function
-----               --------
9 5                 expenditure[] size n =9, d = 5
2 3 4 2 3 6 8 4 5   expenditure = [2, 3, 4, 2, 3, 6, 8, 4, 5]

Sample Output 0


Explanation 0

Determine the total number of  the client receives over a period of  days. For the first five days, the customer receives no notifications because the bank has insufficient transaction data: .

On the sixth day, the bank has  days of prior transaction data, , and  dollars. The client spends  dollars, which triggers a notification because : .

On the seventh day, the bank has  days of prior transaction data, , and  dollars. The client spends  dollars, which triggers a notification because : .

On the eighth day, the bank has  days of prior transaction data, , and  dollars. The client spends  dollars, which does not trigger a notification because : .

On the ninth day, the bank has  days of prior transaction data, , and a transaction median of  dollars. The client spends  dollars, which does not trigger a notification because : .

Sample Input 1

5 4
1 2 3 4 4

Sample Output 1


There are  days of data required so the first day a notice might go out is day . Our trailing expenditures are  with a median of  The client spends  which is less than  so no notification is sent.

Fraudulent Activity Notifications – Hacker Rank Solution
import java.lang.reflect.Array;
import java.util.*;

public class Main implements Runnable {

    int[] cnt;

    int med(int d) {
        int[] a = Arrays.copyOf(cnt, cnt.length);
        int r = d / 2;
        if (d % 2 == 1) {
        int res = 0;
        boolean odd = d % 2 == 1;
        for (int k = 0; k <= 200; k++) {
            while (r > 0 && a[k] > 0) {
            if (r == 0) {
                res += k;
                if (d % 2 == 0) {
                    if (a[k] > 0) {
                        return 2 * k;
                } else {
        return res * (odd ? 2 : 1);

    void solve() throws IOException {
        int n = nextInt();
        int d = nextInt();
        cnt = new int[201];
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        for (int i = 0; i < d; i++) {
        int res = 0;
        for (int i = d; i < n; i++) {
            int m = med(d);
            if (a[i] >= m) {
            cnt[a[i - d]]--;


    BufferedReader br;
    StringTokenizer st;
    PrintWriter out;

    public void run() {
        try {
            br = new BufferedReader(new InputStreamReader(;
            out = new PrintWriter(System.out);

        } catch (Exception e) {

    String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null)
                return null;
            st = new StringTokenizer(s);
        return st.nextToken();

    double nextDouble() throws IOException {
        return Double.parseDouble(next());

    int nextInt() throws IOException {
        return Integer.parseInt(next());

    long nextLong() throws IOException {
        return Long.parseLong(next());

    public static void main(String[] args) {
        new Thread(new Main()).start();

122 thoughts on “Fraudulent Activity Notifications in Algorithm | HackerRank Programming Solutions | HackerRank Problem Solving Solutions in Java [💯Correct]”

  1. Wonderful beat ! I wish to apprentice even as you amend your site, how could i subscribe for a blog website? The account helped me a appropriate deal. I have been tiny bit familiar of this your broadcast offered vibrant clear concept

  2. Hello there, just changed into aware of your weblog thru Google, and located that it is really informative. I?m gonna be careful for brussels. I?ll appreciate if you proceed this in future. A lot of other folks will likely be benefited from your writing. Cheers!

  3. It’s a shame you don’t have a donate button! I’d definitely donate to this fantastic blog! I guess for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this blog with my Facebook group. Chat soon!

  4. One thing I want to say is always that before purchasing more computer memory, check out the machine directly into which it will be installed. If your machine is usually running Windows XP, for instance, the memory limit is 3.25GB. The installation of above this would simply constitute just a waste. Make sure that one’s mother board can handle the particular upgrade amount, as well. Thanks for your blog post.

  5. I have witnessed that costs for on-line degree pros tend to be a fantastic value. For example a full College Degree in Communication from The University of Phoenix Online consists of Sixty credits with $515/credit or $30,900. Also American Intercontinental University Online offers a Bachelors of Business Administration with a complete study course feature of 180 units and a worth of $30,560. Online learning has made getting the college degree so much easier because you could earn your own degree from the comfort in your home and when you finish from office. Thanks for all your other tips I’ve learned through your web site.

  6. Thanks for revealing your ideas listed here. The other factor is that whenever a problem takes place with a laptop motherboard, people today should not have some risk associated with repairing this themselves for if it is not done properly it can lead to permanent damage to the complete laptop. It is usually safe just to approach your dealer of a laptop for the repair of the motherboard. They’ve already technicians who definitely have an experience in dealing with pc motherboard complications and can carry out the right prognosis and perform repairs.

  7. I would love to add when you do not already have got an insurance policy or you do not participate in any group insurance, chances are you’ll well make use of seeking the help of a health insurance professional. Self-employed or those that have medical conditions usually seek the help of a health insurance specialist. Thanks for your article.

  8. Have you ever thought about including a little bit more than just your articles? I mean, what you say is fundamental and all. But think of if you added some great images or videos to give your posts more, “pop”! Your content is excellent but with images and video clips, this site could certainly be one of the very best in its niche. Great blog!

  9. Hey very cool web site!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds also?I am happy to find a lot of useful information here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

  10. Hi there just wanted to give you a quick heads up. The text in your content seem to be running off the screen in Opera. I’m not sure if this is a format issue or something to do with browser compatibility but I figured I’d post to let you know. The design and style look great though! Hope you get the issue solved soon. Many thanks

  11. Oh my goodness! I’m in awe of the author’s writing skills and capability to convey intricate concepts in a concise and clear manner. This article is a real treasure that deserves all the praise it can get. Thank you so much, author, for sharing your knowledge and offering us with such a valuable asset. I’m truly thankful!

  12. One thing I’d really like to say is before obtaining more pc memory, take a look at the machine into which it can be installed. When the machine is definitely running Windows XP, for instance, the memory limit is 3.25GB. Adding over this would purely constitute a waste. Make sure one’s motherboard can handle the particular upgrade amount, as well. Interesting blog post.

  13. Hiya, I am really glad I’ve found this info. Nowadays bloggers publish only about gossips and internet and this is really irritating. A good site with exciting content, that’s what I need. Thank you for keeping this web-site, I’ll be visiting it. Do you do newsletters? Cant find it.

  14. There are definitely loads of particulars like that to take into consideration. That could be a great point to convey up. I provide the ideas above as normal inspiration however clearly there are questions just like the one you deliver up where crucial thing will likely be working in trustworthy good faith. I don?t know if greatest practices have emerged round issues like that, however I am sure that your job is clearly recognized as a fair game. Both boys and girls feel the affect of only a second?s pleasure, for the rest of their lives.

  15. Thanks for your article. One other thing is always that individual American states have their own laws which affect home owners, which makes it very difficult for the our elected representatives to come up with the latest set of recommendations concerning foreclosure on property owners. The problem is that a state possesses own legal guidelines which may have impact in an adverse manner in regards to foreclosure insurance policies.

  16. I do agree with all of the concepts you’ve offered for your post. They’re very convincing and will certainly work. Still, the posts are too quick for starters. May just you please prolong them a little from subsequent time? Thank you for the post.

  17. Hello woyld you mond letting mee now whch web hostt you’re working with?
    I’ve loaded your blkog inn 3 dufferent interrnet browsers andd I mut saay thiks blog loasds a
    loot quicier then most. Cann youu suggest a good hostinng provider att a honezt price?

    Thank you, I appreciate it!

  18. I loved as much as you’ll obtain performed right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an edginess over that you want be delivering the following. sick unquestionably come more earlier again since precisely the similar nearly very regularly inside case you defend this increase.

  19. Have you ever thought about including a little bit more than just your articles? I mean, what you say is fundamental and everything. But think of if you added some great photos or videos to give your posts more, “pop”! Your content is excellent but with images and clips, this blog could certainly be one of the best in its field. Awesome blog!


Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker🙏.

Powered By
Best Wordpress Adblock Detecting Plugin | CHP Adblock