Deshaw SMTS Hackerrank Coding Test 2025
Anonymous User
1778

Deshaw SMTS Screening Round DSA questions on Hackerrank

Date: 18th Oct 2025

2nd Question:

WhatsApp Image 2025-10-25 at 19.23.18.jpeg

WhatsApp Image 2025-10-25 at 19.23.18 (1).jpeg

Code:

string maxSegmentArea(vector<int>& radii, int requiredSegments) {
    sort(radii.begin(), radii.end());

    const float PI = 3.14159265359f;
    int largestRadius = radii.back();
    float minArea = 0.0f;
    float maxArea = largestRadius * largestRadius * 1.0f;

    float bestArea = 0.0f;
    int iterationCount = 0;

    while (maxArea - minArea > 1e-5 && iterationCount <= 10000000) {
        float currentTargetArea = (minArea + maxArea) / 2.0f;

        int segmentsFormed = 0;
        bool enoughSegments = false;

        for (int i = radii.size() - 1; i >= 0; i--) {
            float circleArea = radii[i] * radii[i] * 1.0f;
            segmentsFormed += floor(circleArea / currentTargetArea);

            if (segmentsFormed >= requiredSegments) {
                enoughSegments = true;
                break;
            }
        }

        if (enoughSegments) {
            bestArea = max(bestArea, currentTargetArea);
            minArea = currentTargetArea + 1e-6f;
        } else {
            maxArea = currentTargetArea - 1e-6f;
        }

        iterationCount++;
    }

    // Multiply by PI only once at the end
    bestArea *= PI;

    // Round to 4 decimal places
    float roundedArea = round(bestArea * 10000.0f) / 10000.0f;
    ostringstream out;
    out << fixed << setprecision(4) << roundedArea;
    return out.str();
}

Very less testcases passed.
Few things are redundant in the above code, but if someone finds some genuine mistake, please do comment.

Question 1:

WhatsApp Image 2025-10-25 at 19.23.19.jpeg

WhatsApp Image 2025-10-25 at 19.23.19 (1).jpeg

WhatsApp Image 2025-10-25 at 19.23.19 (2).jpeg

WhatsApp Image 2025-10-25 at 19.23.19 (3).jpeg

Please share ur approaches as well for the above one. Do ensure the following testcase pass. The below ones are generated by me. Was able to come up with some approach and but then thought more and below test cases were going wrong.

Training days = 8,8,8
execution days = [[25,100][26,101][27,102]]
Answer = 27
Reason: Training all of them first, and then executing

Training days = 8,8,8
execution days = [[9,100][26,101][27,102]]
Answer = 27
Reason: Training first one and then executing, and then other 2 sequential training and then execution.

Comments (5)