Company: Ukg_5sep
Difficulty: medium
Given the hash function below, which of the following pairs of strings will result in the same hash value? (Choose all that apply) hashFunction(string s) { int hash = 0; for (int i=0; i<s.length; i++) { hash += (i+1)*(s[i]-'a'+1); } return hash; } "abd" and "bcc" "ace" and "bdd" "abc" and "cba" "aba" and "aac" Which of the following is the most effective way to clean and refactor the provided code snippet to avoid redundancy? const stringA = "test" const stringB = "this" let hashStringA = 0 for (let i = stringA.length - 1; i >= 0; i--) { hashStringA += 32 + stringA.charCodeAt(i) } let hashStringB = 0 for (let i = stringB.length - 1; i >= 0; i--) { hashStringB += 32 + stringB.charCodeAt(i) } Encapsulate the hashing logic into a single reusable function. Combine both strings into a single array and use one loop. Hardcode the hash values since the strings are constants. Use a global variable to track the hash sum across different loops. Given the array [76, 97, 25, 115, 83, 51, 1