Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
1,025 views
in Online Assessments by Expert (46,090 points) | 1,025 views

5 Answers

0 like 0 dislike
Best answer

image

 

image

 

image

Images Of Ques

by Expert (46,090 points)
0 like 0 dislike
C Soln:
void calculate_weight(char *str, int weight_a)
{
int strength = 0;
while(*str != 0)
{
strength += (((*str++ - 'a') + weight_a) % 26);
}
printf("strength: %d\n", strength );
}
by Expert (46,090 points)
0 like 0 dislike

Python Solution

 

def char_position(letter):
    return ord(letter) - 97

def get_weight(string,a_w):
    weight_val = 0
    for i in string:
        if char_position(i)+a_w>25:
            weight_val+=char_position(i)+a_w-26
        else:
            weight_val+=char_position(i)+a_w
        
    return weight_val
by Expert (46,090 points)
0 like 0 dislike
int StrengthOfPassword(string password, int wa)
{
    int ans = 0;
    for (int i = 0; i < password.size(); i++)
    {
        int charWt = (wa + password[i] - 'a') % 26;
        ans += charWt;
    }

    return ans;
}
by Expert (46,090 points)
0 like 0 dislike

Java solution:

 

public static void main(String[] args) {
	String s1 = "hellomrz", s2 = "aaaaa";
	int n1 = 2, n2 = 1;
	System.out.println(solve(s1, n1));
	System.out.println(solve(s2, n2));
}

private static int solve(String s, int n) {
	int res = 0;
	for(char c : s.toCharArray())
		res += ((c - 'a') + n) % 26;
	return res;
}

 

91
5

by Expert (46,090 points)