[output] | #include < stdio.h> int main() { int a, b, great; printf("Enter two integers: "); scanf("%d %d", &a, &b); if (a > b) great = a; else great = b; printf("Greatest among two numbers is %d", great); } [instruction] | Design a C code to accept two integers from the user and find the greatest among them. [input] |
[output] | function removeduplicates(arr){ let arrDupRemoved = []; for (let i = 0; i < arr.length; i++){ if(arrDupRemoved.indexOf(arr[i]) === -1){ arrDupRemoved.push(arr[i]); } } return arrDupRemoved; } console.log(removeduplicates(arrStrings)) // prints ["apple", "orange [instruction] | You are given a string array. Code a JavaScript function to remove duplicate strings from the array. [input] | let arrStrings = ["apple", "orange", "apple", "banana"]
[output] | .MODEL SMALL .DATA N DB ? I DB ? S DB ? .CODE MOV AX,@DATA MOV DS,AX MOV DX,N MOV AL,2 MUL DX SUB AL,1 MOV N,AL MOV I,N MOV S,0 AGAIN: MOV AX,S ADD AX,I MOV S,AX DEC I CMP I,0 JNZ AGAIN MOV DX,S MOV AH, [instruction] | Code an assembly language program to calculate the sum of series 1 + 3 + 5 +.....+ (2*n-1). [input] | n = 6
[output] | public static int findHighestNumber (int[] numbers) { int highestNumber = Integer.MIN_VALUE; for (int currentNumber : numbers) { highestNumber = Math.max(currentNumber, highestNumber); } return highestNumber; } int highestNumber = findHighestNumber(arr); // prints 55 [instruction] | Given an array of numbers, code a Java code to find out the highest number. [input] | int arr[] = {20, 35, -15, 7, 55, 1, -22}
[output] | <html> <head> <title>Sales Chart</title> <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> <script type="text/javascript"> google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); [instruction] | Design a HTML document to display a chart with the sales of a particular item. [input] |
[output] | def count_characters(string): freq_chars = {} for char in string: if char in freq_chars: freq_chars[char] += 1 else: freq_chars[char] = 1 return freq_chars [instruction] | Create a dictionary containing the frequencies for each character in the given string. [input] | string = "hello world"
[output] | #include<sys/types.h> #include <unistd.h> pid_t c_sys_tree (pid_t root_pid) { // Code to generate a process tree // based on the given root PID } [instruction] | Create a system call in C to generate a process tree. [input] |
[output] | The Google search engine was originally written in C++. [instruction] | In what language was the Google search engine originally written? [input] |
[output] | <!DOCTYPEhtml> <html> <head> <title>Score Table</title> </head> <body> <h3>Score Table</h3> <table> <tr> <th>Student Name</th> <th>Score</th> </tr> <tr> <td>Student A< [instruction] | Create an HTML page with a table to display student scores. [input] | Data: Student A: Score - 80 Student B: Score - 90
[output] | A binary search tree is a type of binary tree where the value of each node is greater than the values in its left subtree, and less than the values in its right subtree. A binary tree on the other hand, can have nodes with any value, and the relationship between the nodes is not necessarily sorted. [instruction] | How is a binary search tree different from a binary tree? [input] |
[output] | The time complexity of the algorithm is O(n) since it needs to loop through all the elements in the list in order to calculate the average. [instruction] | Identify the ‘time complexity’ of an algorithm written in Java that calculates average of all elements in a list. [input] |
[output] | The main benefits of using a hash table are faster search times, insertion/deletion time, and less space required to store data. Hash tables are most commonly used for storing key-value pairs, and can be used to quickly search for a value corresponding to a given key. They also provide a constant ti [instruction] | What are the benefits of using a hash table? [input] |
[output] | def common_chars(string_1, string_2): char_list = [] for char in string_1: if char in string_2 and char not in char_list: char_list.append(char) for char in string_2: if char in string_1 and char not in char_list: char_list.append(char) return [instruction] | Define a function which takes two strings as arguments and returns a list containing all characters that appear in either string. [input] | string_1 = 'Apple' string_2 = 'Banana'
[output] | class Employee: def __init__(self, name, age, salary): self.name = name self.age = age self.salary = salary [instruction] | Create a data structure to store an employee's details including his personal details and salary information. [input] |
[output] | def strip_tags(string): stripped_str = '' skip = False for i in range(len(string)): if string[i] == '<' and skip == False: skip = True elif string[i] == '>': skip = False elif skip == False: stripped_str += string[i] return [instruction] | You are given some HTML code, write a function to strip the tags from it. [input] |
[output] | def edit_distance(str1, str2): edits = 0 m = len(str1) n = len(str2) if m < n: for i in range(m, n): edits += 1 for i in range(m): if str1[i] != str2[i]: edits += 1 else: for i in range(n, m): edits += 1 [instruction] | You are given two strings, find the minimum number of edits required to make them equal. [input] |
[output] | def list_primes(start, end): prime_list = [2] for num in range(start, end + 1): if all(num % i != 0 for i in range(2, num)): prime_list.append(num) return prime_list [instruction] | Create a program to list all the prime numbers between two numbers [input] |
[output] | import re def extract_words(string): pattern = r'\b\w*a\w*\b' words = re.findall(pattern, string) return words [instruction] | Write a regex pattern to extract all words containing the letter 'a' from a given string [input] |
[output] | Segment tree is a data structure used to efficiently query certain operations regarding a range of values. A segment tree is a binary tree, with each of its internal nodes containing a range and its leaf nodes reresenting the elements in the given range. The runtime complexity of a segment tree is O [instruction] | Describe the runtime complexity of segment tree. [input] |
[output] | let studentGrade = { grade: 'A+' }; [instruction] | Create an object to hold the student's grade. [input] | Grade: A+
[output] | let result = []; for(let i = 1; i <= 100; i++){ if (i % 5 == 0 && i % 7 == 0) result.push(i); }; console.log(result); [instruction] | Generate an array containing numbers between 1 and 100 that are divisible by both 5 and 7. [input] |
[output] | <html> <head> <title>My Webpage</title> </head> <body> <div class="container1" > </div> <div class="container2" > </div> <div class="container3" > </div> <div class="container4" > </div> <div class="container5" > </div> </body> </html> [instruction] | Design a web page containing HTML/CSS containing at least 5 containers. [input] |
[output] | Binary Indexed Tree (BIT) is a data structure that leverages the advantages of both an array and a binary tree. It is also known as a Fenwick tree. It can be used to efficiently compute the sum of given range of elements in an array. BIT is a type of tree data structure in which the values stored at [instruction] | Explain the concept of Binary Indexed Tree. [input] |
[output] | A HashMap can be used to track the frequency of words in a given text. The keys of the map would represent the words in the text and the associated values would represent the frequency of that word. The time complexity for retrieving the frequency of a given word in hashmap will be O(1). [instruction] | Design a data structure to track the frequency of words in a given text. [input] |
[output] | cubes = [x**3 for x in range(1, 11)] print(cubes) [instruction] | Use the list comprehension method to print the cube of numbers from 1 to 10 [input] |
[output] | let containers = document.querySelectorAll('div.container'); [instruction] | Write Javascript code to select all div elements with the class "container". [input] |
[output] | function isPalindrome(str) { str = str.toLowerCase(); for (let i = 0; i < str.length / 2; i++) { if (str[i] !== str[str.length - 1 - i]) return false; } return true; } [instruction] | Write a predicate function to check whether the given string is palindrome. [input] |
[output] | Using functions in programming is important for a few reasons. Functions can be used to divide a program into smaller, more manageable pieces, making it easier to read, debug, and maintain code. Additionally, functions can be reused across multiple programs by creating libraries that can be imported [instruction] | Explain the importance of using functions in programming. [input] |
[output] | def find_max_positive(arr): max_num = 0 for num in arr: if num > 0 and num > max_num: max_num = num return max_num [instruction] | Write a Python function that takes as input an array of numbers and returns the maximum positive number. [input] | arr = [3, -2, -1, 7, 12]
[output] | SELECT product_name FROM products WHERE price > 50; [instruction] | Formulate a query in SQL that would output the names of products that cost more than $50. [input] |