Jump to content

Java 8 thopulu randi vayya


VinthaAnubhuthi

Recommended Posts

Repu oka desi gaanitho interview sacchindhi. Ee question aduguthadanta. Konchem answer cheyyandi. 3 roles unnayi. Naaku job vasthe mimmalni kooda lagutha.

Input ga oka  array of integers isthe,

output vacchi  'top 3 sub-arrays of 3 integers (triplets) with highest sum' kavali anta.

Link to comment
Share on other sites

4 minutes ago, VinthaAnubhuthi said:

Repu oka desi gaanitho interview sacchindhi. Ee question aduguthadanta. Konchem answer cheyyandi. 3 roles unnayi. Naaku job vasthe mimmalni kooda lagutha.

Input ga oka  array of integers isthe,

output vacchi  'top 3 sub-arrays of 3 integers (triplets) with highest sum' kavali anta.

Ivanni leet code budhuluuu

Link to comment
Share on other sites

class Solution {
    public int[] maxSumOfThreeSubarrays(int[] nums, int k) {
        // W is an array of sums of windows
        int[] W = new int[nums.length - k + 1];
        int currSum = 0;
        for (int i = 0; i < nums.length; i++) {
            currSum += nums[i];
            if (i >= k) {
                currSum -= nums[i - k];
            }
            if (i >= k - 1) {
                W[i - k + 1] = currSum;
            }
        }

        int[] left = new int[W.length];
        int best = 0;
        for (int i = 0; i < W.length; i++) {
            if (W[i] > W[best]) best = i;
            left[i] = best;
        }

        int[] right = new int[W.length];
        best = W.length - 1;
        for (int i = W.length - 1; i >= 0; i--) {
            if (W[i] >= W[best]) {
                best = i;
            }
            right[i] = best;
        }
        
        int[] ans = new int[]{-1, -1, -1};
        for (int j = k; j < W.length - k; j++) {
            int i = left[j - k], l = right[j + k];
            if (ans[0] == -1 || W[i] + W[j] + W[l] > W[ans[0]] + W[ans[1]] + W[ans[2]]) {
                ans[0] = i;
                ans[1] = j;
                ans[2] = l;
            }
        }
        return ans;
    }
}

 

  • Upvote 1
Link to comment
Share on other sites

1 hour ago, VinthaAnubhuthi said:

Repu oka desi gaanitho interview sacchindhi. Ee question aduguthadanta. Konchem answer cheyyandi. 3 roles unnayi. Naaku job vasthe mimmalni kooda lagutha.

Input ga oka  array of integers isthe,

output vacchi  'top 3 sub-arrays of 3 integers (triplets) with highest sum' kavali anta.

question chala tough gaaa udni ... pass bro 

Link to comment
Share on other sites

1 minute ago, Sarvapindi said:

nenu fail..programming asal ekkatle va burra ki

Tension padaku kaka learn Salesforce or Workday comparatively easy to learn and demanding technologies 

Link to comment
Share on other sites

5 minutes ago, Doravaru said:

Tension padaku kaka learn Salesforce or Workday comparatively easy to learn and demanding technologies 

Salesforce also edo programming untadi ga

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...