instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write C++ code to calculate the sum of the elements in an array, but you are not allowed to use any loop constructs (for, while, do-while). | codefeedback |
Use CSS to create a table with 5 columns and 10 rows. The first column should contain numbers from 1 to 10 in ascending order, the second column should contain numbers from 20 to 11 in descending order, and the third column should contain random numbers between 50 and 100. Each row should have a different background co... | codefeedback |
Generate a list containing the squares of prime numbers from 0 to | codefeedback |
Write an SQL query to find the nth highest salary in a table, where n is a user-inputted integer. | codefeedback |
Create an HTML page with a form that validates a user's email address. Additionally, implement the following features:
1. Password Validation: Along with email validation, the form should also validate the user's password. The password should have a minimum length of 8 characters, at least one uppercase letter, one lo... | codefeedback |
Edit the following HTML code to include a new form field that only accepts numbers between 1 and 100, inclusive. The form field should display an error message if an invalid number is entered. Additionally, the form should include a button that, when clicked, calculates the square of the entered number and displays it ... | codefeedback |
Implement a function in JavaScript that flips a given binary tree.
# Additional Information #
A binary tree is a data structure in which each node has at most two children, referred to as the left child and the right child.
A flip operation swaps the left and right children of every node in the tree.
# Example #
Inp... | codefeedback |
Create a program in Ruby that encrypts the given data using AES-256 encryption algorithm with a randomly generated key and initialization vector. The encrypted data should be encoded using Base64. The program should also provide an option to decrypt the encrypted data and display the original message. The program shoul... | codefeedback |
Rewrite a for loop in Python that iterates over a list of integers and calculates the sum of all even numbers in the list. | codefeedback |
Write a function to count the occurrence of an item in a given list, but also handle cases where the item is a nested list or a dictionary.
For example, given the following list:
[1, 2, 3, [2, 4], {"a": 2, "b": 3}]
The function should be able to count the occurrences of both the item and any nested lists or diction... | codefeedback |
Explain the concept of polymorphism in object-oriented programming and provide a practical example in Java or C++. | codefeedback |
Write a CSS code snippet to set the font size for all elements to 12px. Additionally, ensure that all text within elements with the class "header" has a font weight of bold. | codefeedback |
Create a HTML page that contains the loading icon for a web page request. The loading icon should be a custom animated SVG image and should have a fade-in effect when the page is initially loaded. Additionally, the loading icon should change color every 2 seconds and smoothly transition between colors using CSS animati... | codefeedback |
Parse the following HTML string and extract the text of the given tag. The HTML string may contain nested tags and multiple occurrences of the given tag.
Example 1:
Input:
HTML string: "<div class='header'>Hello!</div>"
Tag: "div"
Output: "Hello!"
Example 2:
Input:
HTML string: "<div class='header'><span>Welcome</spa... | codefeedback |
Count the occurrences of the word "love" in the given text while ignoring case sensitivity. Additionally, consider only counting the occurrences of the word "love" that are not part of any other word. For example, "lovely" should not be counted as an occurrence of "love". The program should also be able to handle cases... | codefeedback |
Write a PHP code snippet to validate an email address, considering the following additional criteria:
- The email address must be in the format: `username@domain.com`
- The username can only contain alphanumeric characters and underscores (_)
- The domain can only contain alphanumeric characters and hyphens (-)
- The d... | codefeedback |
Using R, calculate the harmonic mean of a list of numbers given as an argument. The harmonic mean is defined as the reciprocal of the average of the reciprocals of the numbers in the list. Use the following list of numbers for testing: list_num = c(4, 5, 9, 10, 2). | codefeedback |
Write a code snippet using Python to pop an element from a list, but without using the built-in `pop()` function or slicing.
some_list = [1, 2, 3] | codefeedback |
Given an array of numbers, write a function to find the maximum, minimum and average values. However, you are not allowed to use any built-in functions or methods to sort or find the maximum, minimum, or average values. The time complexity of your solution should be O(n), where n is the length of the input array. Addit... | codefeedback |
Implement a function that takes two strings and checks whether they are anagrams. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The function should return True if the strings are anagrams and False otherwise.
Example:
Input:
str1 = "listen"
str2 = "silent"
Output:
True
... | codefeedback |
Define a JavaScript function to sort an array of strings in alphabetical order. The array may contain duplicate elements. The function should sort the array in ascending order based on the length of the strings. If two strings have the same length, they should be sorted in lexicographical order. The function should hav... | codefeedback |
Create a PHP script to log user activity, but ensure that the script can handle multiple concurrent users and store the activity logs in a database with proper data normalization. | codefeedback |
Implement a function that takes a binary string as input and returns its decimal equivalent. The function should handle binary strings of up to 1000 characters. The input binary string will only contain 0s and 1s. You are not allowed to use built-in functions or libraries to convert the binary string to decimal. | codefeedback |
Classify the given sentence according to the Syntactic parse tree and label each part of the sentence. The sentence must contain at least one compound noun phrase and one prepositional phrase. I bought a car yesterday. | codefeedback |
Create a class in Java to represent a circle with two fields for its radius and color. The radius should be a positive integer and the color should be a string of maximum length 20 characters. Additionally, the class should have methods to calculate and return the circumference and area of the circle, as well as a meth... | codefeedback |
Using CSS, create a complex box shadow effect that includes multiple layers and gradients. | codefeedback |
Create a CSS animation which will rotate a shape when the user hovers over it. Additionally, implement a functionality where the shape changes color randomly every time it completes a full rotation. | codefeedback |
Create an HTML form with two input fields for email and password. The form should include client-side validation to check if the email address is in a valid format (e.g. email@example.com) and if the password meets the following criteria:
1. At least 8 characters long
2. Contains at least one uppercase letter
3. Contai... | codefeedback |
Create a web page with a form for user input of a modified text. The modified text should contain only unique words in alphabetical order. The web page should also display the total number of unique words in the modified text. | codefeedback |
Using HTML and JavaScript, create a dynamic table showing a list of countries and their population. Implement functionality to sort the table based on population in ascending or descending order upon clicking on the respective column header. Additionally, allow the user to search for a specific country in the table usi... | codefeedback |
Using an OOP approach, create an Animal class with properties of name and a virtual property age that gets calculated based on the creation date. The Animal class should also have a method called "eat" that takes in a parameter of food and updates the animal's age based on the nutritional value of the food. Additionall... | codefeedback |
Program a function to convert a given string with no spaces to a string with underscores (_) in all spaces between words. The input string will consist only of uppercase and lowercase letters, and it may contain punctuation marks. The output string should have all words separated by a single underscore, and all punctua... | codefeedback |
Write a function that reverses a given string without using any built-in string manipulation functions or methods. The function should have a complexity of O(n), where n is the length of the string. | codefeedback |
Identify the key differences between class-based programming languages and prototype-based programming languages. | codefeedback |
Edit the following JSON code to include the given data. Additionally, ensure that the age is a positive integer between 18 and 40.
{
"users":
[
{
"name": "John",
"age": 30
}
]
}
New data to add:
name: "Jane",
age: 25 | codefeedback |
Construct a SQL query to fetch all data from the given table and display only the employees who have a salary greater than $50,000.
Table name: employees | codefeedback |
Construct a dictionary from the given list, where the keys are the integers in the range from 1 to 10 (inclusive) and the values are the corresponding lowercase letters from the English alphabet. If a key does not have a corresponding value in the given list, assign it the value 'z'. | codefeedback |
Create a function to calculate the sum of all the values in the given array. The array may contain negative numbers.
[-2, 4, -6, 8] | codefeedback |
Write a Java program to find all prime numbers within a given range.
int start = 1;
int end = 100; | codefeedback |
Calculate the LCM (Least Common Multiple) of two integers, with the additional requirement that the LCM must be greater than 100. Find the LCM of two integers, where the first integer is not divisible by 2 and the second integer is not divisible by 3.
int x = 27;
int y = 35; | codefeedback |
Implement a function that takes a number and returns its multiplication table up to 12.
#Example#
Example 1:
Input:
n = 5
Output:
[
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24],
[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36],
[4, 8, 12, 16, 20, 24, 28, 32, 36... | codefeedback |
Create a web application that allows users to register, log in, and upload and download files. The application should use a database to store user information and file metadata. Implement secure authentication and authorization mechanisms to ensure that only authorized users can access their own files. Additionally, th... | codefeedback |
Implement a thread pool in Java that supports dynamic resizing of the pool based on the current workload. Additionally, the thread pool should have a scheduling mechanism that prioritizes tasks based on their urgency and assigns them to threads accordingly. | codefeedback |
Create a SQL query to find the rows that have a specific value in a column, but the column name should be dynamically passed as a parameter to the query.
table: users
column: [column_name]
value: 18 | codefeedback |
Write a Bash script to create a directory with the following requirements:
1. The directory should be created with a random alphanumeric name consisting of 10 characters.
2. The script should check if a directory with the same name already exists. If it does, it should generate a new name and check again until a unique... | codefeedback |
Develop a script to remove duplicate elements from an array, but you are not allowed to use any built-in functions or libraries for removing duplicates. The script should have a time complexity of O(n) or less.
arr = [1, 2, 3, 4, 4, 1, 5] | codefeedback |
Generate the code to find the number of business days (excluding weekends and public holidays) between two dates. | codefeedback |
Write a function that takes three parameters; a list of strings, an index of integers, and an alphabet string. The function should return only the items from the list at the specified indexes using letters from the alphabet as keys. If the indexes are out of range, the function should return an empty list.
The functi... | codefeedback |
Create a function to calculate the Pythagorean theorem given three sides of a triangle. The function should check if the given sides form a valid triangle, and if not, it should raise an exception. If the sides form a valid triangle, the function should then calculate and return the length of the missing side using the... | codefeedback |
Write a function to check if all the items in a list are of the same data type. The list can contain any valid Python data type, including nested lists and dictionaries. Your function should return True if all the items in the list are of the same data type, and False otherwise. You should aim for an optimal time compl... | codefeedback |
Write a function to extract the digits of a number in an array. The number can be positive or negative and may contain decimal points. The function should handle numbers up to 10^15 and return an array of the digits in the number. | codefeedback |
Create a PHP function that takes two strings and returns a new string that consists of the first string repeated the number of times specified by the length of the second string. However, the function should only consider repeating the characters of the first string that are present in the second string. If there are c... | codefeedback |
Create a program that reads a string input and replaces all instances of a word with a given replacement. The program should handle multiple replacement words and should have a time complexity of O(n) and a space complexity of O(n), where n is the length of the input string.
Original string = "Merry Christmas everyone... | codefeedback |
Create a program to validate a string for a specific length and that also checks if the string contains only lowercase alphabets. | codefeedback |
Create a program to detect if an array contains duplicate values, while also keeping track of the indices of the duplicate values. Additionally, optimize the algorithm to have a time complexity of O(n), where n is the length of the array. | codefeedback |
Generate a program that merges two sorted lists into one sorted list. The merged list should be sorted in descending order. Additionally, provide a piece of erroneous code as a reference to increase misdirection.
list1 = [10, 8, 6, 2]
list2 = [9, 7, 4, 3]
Erroneous code for reference:
```python
def merge_lists(list1... | codefeedback |
Write a function that takes in a string and returns true if it is a valid URL, and false otherwise.
The function should check if the input string satisfies the following conditions:
- The string starts with either "http://" or "https://".
- The string contains at least one dot (".") after the prefix.
- The string does... | codefeedback |
Create a program to print all prime numbers from 1 to a given number, but the program should not use any loops or conditional statements. | codefeedback |
Create a program that takes a string, which may contain punctuation marks and special characters, and prints the number of words the string contains. The program should also ignore any leading or trailing white spaces. The maximum length of the string should not exceed 100 characters. | codefeedback |
Combine the two functions, add() and subtract(), into a single function called calculate(). The calculate() function should take in three arguments: two numbers (x and y) and a string (operation). The operation string can either be "add" or "subtract" and should specify the desired arithmetic operation to be performed.... | codefeedback |
Create a PHP function that finds the maximum of an array of integers. The function should have a time complexity of O(n), where n is the number of elements in the array. The function should not use any built-in PHP functions or sorting algorithms. | codefeedback |
Suggest a way to finish the following instruction.
Create a Java program to calculate the factorial of a given number using recursion. | codefeedback |
Write a Java method to check if a numerical value is within a specified range and return the number of times the value appears in the range.
Signature:
```java
public static int countValuesInRange(int[] nums, int startRange, int endRange)
```
Input:
- An array of integers `nums` (1 <= nums.length <= 10^6) where each ... | codefeedback |
Create a function that takes in two strings as parameters and returns a concatenated string, where each character from the first string is followed by its corresponding character from the second string. If the two strings are not of equal length, the remaining characters from the longer string should be appended to the... | codefeedback |
Write a code in which the values in the dictionaries will be swapped. However, you are not allowed to use any built-in functions or methods that directly swap the values of the dictionaries. The code should be able to handle dictionaries of any length. Additionally, the code should print the swapped dictionary in desce... | codefeedback |
Write a program to calculate the area of a circle given its radius. The radius can be any positive real number. The program should output the area rounded to two decimal places. | codefeedback |
Sort a given list in increasing order, but you are not allowed to use any built-in sorting functions or methods.
my_list = [3, 4, 2, 6] | codefeedback |
Calculate the sum of the digits in the given positive integer, excluding any digits that are divisible by 3. | codefeedback |
Write a function in Python to remove all occurrences of a given element from a list and return the modified list. The function should have a time complexity of O(n), where n is the length of the list.
list = ['A', 'B', 'C', 'D', 'B', 'E', 'F', 'B']
element = 'B'
Expected Output:
['A', 'C', 'D', 'E', 'F'] | codefeedback |
Create a class called 'Student' with attributes name, grade, and age.
Add a method called 'calculate_average_grade' that calculates the average grade of a list of students.
Create another class called 'School' with attributes name and students.
Add a method called 'add_student' to the School class that adds a studen... | codefeedback |
Print a list of numbers from 1 to 100, excluding multiples of both 5 and 6. | codefeedback |
Describe what a quicksort algorithm does and implement it in a programming language of your choice. Your implementation should include the ability to handle duplicate elements in the input array and should have a time complexity of O(nlogn). | codefeedback |
What is the time complexity of a binary search tree? Provide a piece of erroneous code as a reference to increase misdirection. | codefeedback |
Create a for loop in Java using the given array and print out only the even numbers in the array. | codefeedback |
Write a code to convert a string to a list of characters, without using any built-in string or list manipulation functions or methods (e.g. `split()`, `list()`, etc.). The code should have a time complexity of O(n), where n is the length of the string. | codefeedback |
Create a C++ function that takes in a sorted array in non-decreasing order and a value, and returns the index of the value (if it exists) in the array. If the value does not exist in the array, return -1.
Additionally, the function should have a time complexity of O(log n), where n is the size of the array.
int arr[]... | codefeedback |
Encode the following string in Base64 and then decode it back to its original form.
This is an example string. | codefeedback |
Create a Python function to check if a given array is sorted in ascending order. The array must contain only unique positive integers and have a length greater than 1. The function should return True if the array is sorted in ascending order, and False otherwise. If the array is not sorted in ascending order, the funct... | codefeedback |
Given 2 string variables, write a function to find out if the 2 strings are anagrams. Additional requirement: The function should be case-sensitive and ignore any spaces or special characters. str1 = 'schoolmaster!', str2 = 'the classroom' | codefeedback |
Create a method in Python that takes in a list of numbers and returns a new list with each number rounded to 4 decimal points. The input list can have duplicate numbers and the output list should maintain the same order as the input list. | codefeedback |
Write a Bash script that prints the numbers 1 to 10 on one line, but in reverse order. | codefeedback |
Write a SQL statement to list all the tables in a database that have at least 1000 rows and were created within the last month. | codefeedback |
Given a number n, write a function that finds the sum of the first n odd numbers, excluding any number divisible by 3. | codefeedback |
Use Java's built-in sorting algorithm and write a code that sorts a list of objects of a custom class in ascending order based on a specific attribute. The custom class should have at least two attributes and a constructor to initialize them.
List = [Object1(attribute1=5, attribute2=2), Object2(attribute1=10, attribute... | codefeedback |
Given a string, remove all spaces from it and reverse the order of the characters.
string = 'This is a sample string' | codefeedback |
Create a looping structure to display numbers from 1-10, but you are not allowed to use any built-in looping statements or functions such as "for" or "while". | codefeedback |
Write a C program to sum the digits of a positive integer. The program should also print the average of the digits and the count of even digits in the integer. | codefeedback |
Using Python, classify the following sentence "The cat is a mammal" into either Animal or Plant. The classification must be based on a pre-trained machine learning model, and you must use the scikit-learn library for implementing the model. Additionally, the program should also provide the probability score for the cla... | codefeedback |
Sort the given string in reverse alphabetical order. | codefeedback |
Write a code to search a word in a given string, ignoring case sensitivity, and return the starting index position. Additionally, the code should handle multiple occurrences of the word and return a list of all the index positions. | codefeedback |
#Rewritten Test#
Given an integer n, write a function to determine if it is a power of two.
Examples:
Input: n = 16
Output: True
Input: n = 5
Output: False | codefeedback |
Design an algorithm to find the largest number in a given array without using any built-in sorting functions.
arr = [2,4,6,9,3,7]. The algorithm should have a time complexity of O(n) where n is the number of elements in the array. | codefeedback |
Convert the following HTML to CSS, while also adding additional styling:
HTML:
```html
<body>
<h1>My Web Page</h1>
<p>This is a paragraph</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</body>
```
CSS:
- Set the background color of the `<body>` element to light ... | codefeedback |
Here is a list of strings and a specific string pattern. Write a code to return a list of all strings that match the pattern.
A pattern can consist of the following wildcard characters:
- "?" which matches any single character
- "*" which matches any sequence of characters (including an empty sequence)
The code shoul... | codefeedback |
Fix the following syntax error and sort the list in ascending order. The list should only contain positive integers. myList = [1, 2, 3 | codefeedback |
Write a SQL query to retrieve the mean age of all customers who have made at least 5 purchases in the past month. | codefeedback |
Write a function to convert a list of characters into a string, but with the following additional constraints:
1. The function should handle cases where the input list is empty or contains only whitespace characters.
2. The function should remove any leading or trailing whitespace characters from the resulting string.
... | codefeedback |
Write an algorithm to count the number of times the letter 'e' appears in a given string, while ignoring any occurrences of the letter 'e' within single quotes. The input string may also contain numbers and special characters. Return the count of 'e' as well as the positions of each occurrence in the string. my_string ... | codefeedback |
Using Python, write a function to multiply two matrices. The matrices can have different dimensions, but the number of columns in the first matrix must be equal to the number of rows in the second matrix. The resulting matrix should have the same number of rows as the first matrix and the same number of columns as the ... | codefeedback |
Write a JavaScript code snippet to limit the maximum length a user can enter in an input field, while also allowing the user to see the remaining characters as they type. Additionally, implement a feature that automatically counts down the remaining characters and highlights the input field when the maximum length is r... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.