Join Regular Classroom : Visit ClassroomTech

Commvault Systems Overall Interview Questions + Coding Solution – codewindow.in

Hot Topics

Commvault Systems Solution

Technical Round

def find_smallest_number(p):
    while True:
        p += 1
        binary = bin(p)[2:]
        if '11' not in binary:
            return p
You can test the function with the following code:
p = 10
result = find_smallest_number(p)
print(result)  
# Output: 12
function functionName() {
  console.log("Function executed");
}

window.functionName(); // Output: "Function executed"
char *a = "something";
is considered valid. It declares a pointer a of type char * and initializes it with a string literal “something”.
However, it is worth noting that string literals in C and C++ are stored in read-only memory, and attempting to modify them can result in undefined behavior. If you need to modify the contents of the string, you should declare an array of characters and copy the string into the array.
class CustomException(Exception):
    def __init__(self, message):
        self.message = message

try:
    raise CustomException("This is a custom exception")
except CustomException as e:
    print(e.message)
#OUTPUT - This is a custom exception
In this example, the CustomException class is defined with a constructor that takes a message argument. When an instance of this class is raised as an exception, you can access the message attribute to retrieve the error message.
You can add additional methods or attributes to the custom exception class as needed to provide more information about the exception. When defining custom exceptions, it’s a good idea to choose descriptive names for your exceptions and to document their intended use.
def is_rotation(string1, string2):
    if len(string1) != len(string2):
        return False

    doubled = string1 + string1
    return string2 in doubled

def find_rotation_point(string1, string2):
    if not is_rotation(string1, string2):
        return -1

    return len(string1) - doubled.index(string2)

string1 = "hello"
string2 = "llohe"

if is_rotation(string1, string2):
    rotation_point = find_rotation_point(string1, string2)
    print("'{}' is a rotation of '{}', rotated {} degrees".format(string2, string1, rotation_point))
else:
    print("'{}' is not a rotation of '{}'".format(string2, string1))
In this example, the is_rotation function concatenates string1 with itself and then checks if string2 is a substring of the result. If string2 is found in the result, then string1 is a rotation of string2. The find_rotation_point function calculates the number of characters by which string2 has been rotated relative to string1. It returns the result by subtracting the starting position of string2 in doubled from the length of string1.
class Node:
    def __init__(self, value):
        self.value = value
        self.left = None
        self.right = None

def print_ccw_border(root):
    if not root:
        return

    print(root.value, end=" ")

    if not root.left and not root.right:
        return

    leftmost = root.left
    while leftmost.left:
        print(leftmost.value, end=" ")
        leftmost = leftmost.left

    stack = [root.right]
    while stack:
        node = stack.pop()
        if node:
            print(node.value, end=" ")
            stack.append(node.right)
            stack.append(node.left)

root = Node(10)
root.left = Node(5)
root.right = Node(15)
root.left.left = Node(2)
root.left.right = Node(7)
root.right.left = Node(12)
root.right.right = Node(20)

print_ccw_border(root)
In this example, the print_ccw_border function first prints the value of the root node. If the root has no children, it returns. Otherwise, it first prints the value of the leftmost leaf node by following the left pointers from the root to the leftmost leaf. Then, it uses a stack to traverse the right subtree in pre-order and print the values of the border elements, i.e., the right-most leaf node and the right child of each parent node.
def max_gifts(N, gifts):
    gifts.sort()
    count = 0
    for i in gifts:
        if N >= i:
            count += 1
            N -= i
        else:
            break
    return count

N = 50
gifts = [10, 20, 30, 40, 50]
print(max_gifts(N, gifts))
In this example, the max_gifts function sorts the list of gifts based on their prices and then iterates through the list. If the budget N is greater than or equal to the price of the gift, the gift is purchased and the budget is reduced by the price. If the budget is less than the price, no more gifts can be purchased, so the loop breaks and the function returns the number of gifts that can be purchased.
def find_sum(arr, target):
    start = 0
    end = len(arr) - 1
    while start < end:
        if arr[start] + arr[end] == target:
            return (arr[start], arr[end])
        elif arr[start] + arr[end] < target:
            start += 1
        else:
            end -= 1
    return None

arr = [1, 5, 10, 11]
target = 15
print(find_sum(arr, target))
In this example, the find_sum function takes an array and a target sum as input. The start and end pointers are initialized to the beginning and end of the array, respectively. In each iteration of the while loop, the sum of the elements pointed to by start and end is calculated. If the sum is equal to the target, the pair of elements is returned. If the sum is less than the target, the start pointer is moved to the right. If the sum is greater than the target, the end pointer is moved to the left. If the pointers cross each other, it means that no such pair exists, and None is returned.

      

Go through our study material. Your Job is awaiting.

Recent Posts
Categories