Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
3,958 views
All past online assesments of Walmart can be found using the tag "walmart_oa" in the search bar.

Here is the link :  https://www.desiqna.in/tag/walmart_oa
in Online Assessments by Expert (34,270 points)
edited by | 3,958 views

2 Answers

1 like 0 dislike
#include <bits/stdc++.h>

using namespace std;


bool prime(int n)

{

    int count = 0;

    for (int i = 2; i <= sqrt(n); i++)

    {

        if (n % i == 0)

        {

            return false;

        }

    }

    return true;

}


int main()

{

    int t;

    cin >> t;

    while (t--)

    {

        int x, y;

        cin >> x >> y;

        int ans1, ans2;

        for (int i = x; i >= 2; i--)

        {

            bool check = prime(i);

            if (check)

            {

                ans1 = i;

                break;

            }

        }

        for (int i = y; i >= 2; i--)

        {

            bool check = prime(i);

            if (check)

            {

                ans2 = i;

                break;

            }

        }

        cout << ans1 - ans2;

    }

}
by (200 points)
0 1
Good!!!!!!!!!!!!!!!!!!
0 1
I think this soln will result in TLE
0 0
it wont return tle .. there is a reason he started iterating from backwards there is a prime at always 100-200 distance from any number .. so just in 200 iterations he will find a prime number .. do some research you will know.....
2 like 2 dislike

Walmart OA Coding Questions ...

by Expert (34,270 points)
edited by