[output] | def size(node): if node is None: return 0 else: return (size(node.left) + 1 + size(node.right)) [instruction] | Implement an algorithm in Python to find the size of a Binary tree. [input] |
[output] | function Student(name,class,roll_no){ this.name=name; this.class=class; this.roll_no=roll_no; return this; } [instruction] | Create a constructor object in JavaScript to represent a student. [input] |
[output] | <html> <head><title>Welcome to our website</title></head> <body> <h1>Welcome to our website</h1> </body> </html> [instruction] | Create an HTML page with a header containing the text "Welcome to our website". [input] |
[output] | def lowercase_string(input_str): output_str = "" for char in input_str: output_str += char.lower() return output_str if __name__ == '__main__': print(lowercase_string("HELLO WORLD")) [instruction] | Write a code to convert all the letters of a string to lowercase. [input] | Input string: "HELLO WORLD"
[output] | for x in range(1, 6): if x != 3: print(x) [instruction] | Output all numbers between 1 to 5 except for 3 using Python. [input] |
[output] | def power_of_2(n): res = [] for i in range(n+1): if i & (i-1) == 0: res.append(i) return res [instruction] | Print all powers of 2 less than or equal to n. [input] | n = 10
[output] | def fibonacci(n): a = 0 b = 1 if n == 0: return a elif n == 1: return b else: for i in range(2,n+1): c = a + b a = b b = c return b [instruction] | Compute the n-th Fibonacci number. [input] |
[output] | def common_elements(arr1, arr2): common = [] for item in arr1: if item in arr2: common.append(item) return common [instruction] | Given two arrays of integers, find the common elements. [input] | arr1 = [1, 2, 3, 4, 5]; arr2 = [4, 5, 6, 7, 8]
[output] | {"employees": ["John", "Mike", "Sarah"]} [instruction] | Write a JSON string containing a list of three employee names. [input] |
[output] | for(int i=0; i<=20; i++) { if (i%2 != 0) std::cout << i <<"\n"; } [instruction] | Generate a C++ code with a loop from 0 to 20 which prints odd numbers only. [input] |
[output] | let arr = [1,2,3,4,5]; let arrString = arr.map(String); // ['1','2','3','4','5'] [instruction] | Generate a JavaScript code which converts an array of integers to an array of Strings. [input] | [1,2,3,4,5]
[output] | You can check if a string is a substring of another string in Python by using the "in" operator. For example, if you want to check if the string "hello" is a substring of a variable called "my_string", you can do: if 'hello' in my_string: # do something [instruction] | How can you check if a string is a substring of another string in Python? [input] |
[output] | bool compareStrings(string str1, string str2) { if(str1.compare(str2) == 0) return 1; else return 0; } [instruction] | Generate C++ code that compares two strings and returns 1 if they are equal, 0 if they are not. [input] |
[output] | <!DOCTYPE html> <html> <head> <style> body { background-color: black; color: white; } </style> </head> <body> </body> </html> [instruction] | Generate a HTML code which has a black background and white font. [input] |
[output] | function min(a,b) { return (a < b) ? a : b; } [instruction] | Generate JavaScript code which takes two numbers and returns the smaller one. [input] |
[output] | ['third', 'second', 'first'] [instruction] | Reverse a given list of strings. [input] | ['first', 'second', 'third']
[output] | "o to th" [instruction] | Generate a substring from the given string? [input] | String: “Welcome to this program” Requirement: Substring from index 4 to 9
[output] | ['odd', 'even', 'odd', 'even', 'odd', 'even'] [instruction] | Given an integer array, classify all the elements as even and odd. [input] | [1, 2, 3, 4, 5, 6]
[output] | """ def is_power_of(x): # Initializing the counter i = 0 # Iterating through possible exponents while (x > 1): if (x % 2 == 0): x /= 2 else: return False i += 1 return True # Function call print(is_power_of(8)) """ O [instruction] | Write a function to check whether a given number can be expressed as the power of some other number [input] | Number: 8
[output] | """ def is_palindrome(num): # Initializing variables n = num rev = 0 while (n > 0): # Storing the remainder rev = (rev * 10) + n % 10 # Updating n n //= 10 # Checking if the reversed number is equal to the given number if (num == rev): [instruction] | Develop a code to check whether a number is a palindrome. [input] | Number: 1234321
[output] | {'a': 1, 'p': 2, 'l': 1, 'e': 1} [instruction] | Given a string, identify the count of each letter in the string. [input] | String: "apple"
[output] | [True, False, False, True] [instruction] | Given a list of numbers, determine whether they are a perfect square or not. [input] | [1, 2, 3, 4]
[output] | """ def linear_search(arr, n): # Iterate through the array for i in range(len(arr)): # If the given number is found if arr[i] == n: return True # Return False if the given number is not present return False # Function call print(linear_search([1, 2, [instruction] | Perform linear search on a given list of numbers to check if a given number is present in the list. [input] | List: [1, 2, 3, 4] Number: 2
[output] | ['Dogs are', 'are the', 'the best', 'best pet'] [instruction] | Given a string of words, generate the n-grams of the string. [input] | String: "Dogs are the best pet" Gram size: 2
[output] | const ProfileTable = () => { return ( <table> <tr> <th>Full Name</th> <th>Username</th> <th>Email</th> <th>Phone</th> </tr> <tr> <td>{user.full_name}</td> <td>{user.username}</td> <td>{user.email}</td> <td>{user. [instruction] | Using React, write a component that displays a table containing the user's profile information. [input] |
[output] | def remove_special_characters(string): final_string = "" for character in string: if character.isalnum(): final_string += character return final_string [instruction] | Given a string, write a Python program to remove all special characters from it. [input] |
[output] | @mixin toast-style { background-color: #F2DEDE; color: #A94442; border: 1px solid #EBCCD1; font-size-base: 1rem; font-family: sans-serif; } [instruction] | Create a Sass mixin to create a "toast" style. [input] |
[output] | SELECT * FROM customer_orders WHERE total_price > 50; [instruction] | Create a SQL query to find all rows from the table "customer_orders" that have a total price of more than $50. [input] |
[output] | class Student { String name; String studentId; String course; String[] subjects; int age; String email; Float averageScore; Map<String, Float> scoresBySubject; } [instruction] | Design a data structure to store information about a student. [input] |
[output] | #include<stdio.h> #include<stdlib.h> #include<time.h> int main() { srand(time(0)); int x; x = rand() % 6; printf("%d\n",x); } [instruction] | Modify the following C++ program to print a random number between 0 and 5. [input] | #include<stdio.h> int main() { int x; x = rand() % 10; printf("%d\n",x); }