๐—–๐—ฆ ๐—”๐—น๐—ด๐—ผ ๐Ÿ’ป ๐ŸŒ ใ€Ž๐—–๐—ผ๐—บ๐—ฝ๐—ฒ๐˜๐—ถ๐˜๐—ถ๐˜ƒ๐—ฒ ๐—ฃ๐—ฟ๐—ผ๐—ด๐—ฟ๐—ฎ๐—บ๐—บ๐—ถ๐—ป๐—ดใ€
9.63K subscribers
5.61K photos
3 videos
95 files
10.6K links
๐ŸšฉMain Group - @SuperExams
๐Ÿ“Job Updates - @FresherEarth

๐Ÿ”ฐAuthentic Coding Solutions(with Outputs)
โš ๏ธDaily Job Updates
โš ๏ธHackathon Updates & Solutions

Buy ads: https://telega.io/c/cs_algo
Download Telegram
given an array A of size N.

You are allowed to choose at most one pair of elements such that distance (defined as the difference of their indices) is at most K and swap them.

Find the smallest lexicographical array possible after

Notes:

An array x is lexicographically smaller than an array y if there exists an index i such that xi <y i1 and x_{j} = y_{j} for all 0 <= j < i . Less formally, at the first index i in which they differ xi < yi
Input Formats@gman

The First-line contains Integers N Ea an integer, N, denoting the line i of the N subsequent lines (where describing A[i]. of elements in A. N) contains an integer

The next line contains an integer, K, denoting the upper bound on distance of index.

Constraints
Here as all the array values are equal swapping will not change the final result,

Here A=[5,4,3,2,11 K we can swap elements at index 0 and index 3 which makes A= [2,4,3,5,1].

Here A=[2,1,1,1,1] K we can swap elements at index 0 and index 3 chat which makes A= [1.1.1.2.11




bool swapped = false;
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j <= min(i + K, N - 1); j++) {
            if (A[i] > A[j]) {
                swap(A[i], A[j]);
                swapped = true;
                break;
            }
        }
        if (swapped) break;
    }
    if (!swapped) return A;
    else return A;

C++โœ…
Infosys
๐Ÿ‘1
int n = s.length();
    Map<Character, Integer> f = new HashMap<>();
    for (int i = 0; i < n; i++)
    {
        char chh = s.charAt(i);
        int count = f.getOrDefault(chh, 0);
        f.put(chh, count + 1);
    }

    int m = t.length();
    Map<Character, Integer> f = new HashMap<>();

    for (int i = 0; i < m; i++)
    {
        char chh = t.charAt(i);

        int count = f.getOrDefault(chh, 0);
        f.put(chh, count + 1);
    }

    int result = Integer.MAX_VALUE;

    for (char key : f.keySet())
    {
        int c = freqS.getOrDefault(key, 0);
        int r = f.get(key);

        result = Math.min(result, c / r);
    }

    return result == Integer.MAX_VALUE ? -1 : result;

Amazon SDE1โœ