top of page
  • Facebook
  • Instagram

Latest Coding questions asked in TOP MNCs for Freshers and Experienced candidates

<code>
// C# function to determine if two strings differ by exactly one character
public static bool FuncFoo(string s1, string s2)
{
    int m = s1.Length;
    int n = s2.Length;
    
    // Check if the absolute length difference is exactly 1
    if (Math.Abs(m - n) != 1)
    {
        return false;
    }
    
    int i = 0;
    int j = 0;
    int count = 0;
    
    // Iterate through the strings, counting differences
    while (i < m && j < n)
    {
        if (s1[i] == s2[j])
        {
            i++;
            j++;
        }
        else
        {
            count++;
            // Adjust indices based on length comparison
            if (m > n)
            {
                i++;
            }
            else if (n > m)
            {
                j++;
            }
            else
            {
                i++;
                j++;
            }
        }
    }
    
    // Check if there is exactly one difference or if lengths are equal
    if (count == 1 || (count == 0 && m != n))
    {
        return true;
    }
    
    return false;
}
</code>

1) what does the below function achieve and illustrate your understanding with an example below:

Tell true or false for below inputs:

input strings are "abc123" and "abc1234"

input strings are "abc1234" and "abc123"

input strings are "abc1234" and "abc321"


<code>

// C# function to determine if two strings differ by exactly one character

public static bool FuncFoo(string s1, string s2)

{

    int m = s1.Length;

    int n = s2.Length;

    

    // Check if the absolute length difference is exactly 1

    if (Math.Abs(m - n) != 1)

    {

        return false;

    }

    

    int i = 0;

    int j = 0;

    int count = 0;

    

    // Iterate through the strings, counting differences

    while (i < m && j < n)

    {

        if (s1[i] == s2[j])

        {

            i++;

            j++;

        }

        else

        {

            count++;

            // Adjust indices based on length comparison

            if (m > n)

            {

                i++;

            }

            else if (n > m)

            {

                j++;

            }

            else

            {

                i++;

                j++;

            }

        }

    }

    

    // Check if there is exactly one difference or if lengths are equal

    if (count == 1 || (count == 0 && m != n))

    {

        return true;

    }

    

    return false;

}

</code>


Latest News

25/3/24

How to become an AWS Data Engineer in 2024

Mastering AWS Data Engineering: Your Roadmap to Data AWS Engineer

27/1/24

TOP MNC CODING INTERVIEW QUESTION PART-2

Navigating Organization Hierarchy: A Python Solution for Employee-Manager Relationships

26/1/24

TOP MNC CODING INTERVIEW QUESTION PART-1

Latest Coding questions asked in TOP MNCs for Freshers and Experienced candidates

bottom of page