instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Using jQuery, write a script to select all elements with the classname "highlight" and change their background color to yellow. Additionally, add a click event listener to each selected element so that when clicked, the background color changes to blue. Furthermore, add a class "active" to each clicked element. Finally... | codefeedback |
Create a function in JavaScript that takes in two numbers and calculates the result of raising the first number to the power of the second number. If either of the numbers is negative, the function should throw an error. If the second number is not an integer, the function should round it down to the nearest integer be... | codefeedback |
Create a JavaScript function named 'calculateAge' that determines a person's age based on the birth year given. The birth year should be validated to ensure it is a valid year in the past (i.e. not a future year) and is a leap year. If the birth year is not valid or not a leap year, the function should throw an error w... | codefeedback |
Create a dynamic and interactive web page using HTML, CSS, and JavaScript. The page should have a header, a body, and a footer section. The header section should contain a navigation bar with at least five menu items that change color when hovered over. The body section should have a main content area with at least thr... | codefeedback |
Write a code to filter out numbers which are divisible by 3 and 5, but not by 2, from a given list of integers. The filtered numbers should be stored in a new list, and the program should print the sum of the filtered numbers. The program should handle cases where the given list is empty by printing "No numbers to filt... | codefeedback |
Convert the hexadecimal number FAEE to its binary form, using bitwise operations only. | codefeedback |
Write a SQL query to update the status of all rows in the 'customers' table from active to inactive where the 'last_updated' column is older than 30 days and update the 'last_updated' column with the current timestamp for each row. | codefeedback |
Write a SQL query to find the top 3 most visited websites on a specific day, excluding any websites that have been flagged as potentially malicious or containing inappropriate content. Additionally, exclude any websites that have been visited by more than 100 unique users on that day. | codefeedback |
Write a Mongoose query to remove a document with a date field that has a value of 2021-01-05 and a nested object field called "status" with a value of "active". Additionally, the query should also delete all documents where the date field is before the current date and the status field is not equal to "inactive". | codefeedback |
Create a class named 'Car' with the following properties:
- Make: A string that represents the manufacturer of the car. The make should be limited to a specific list of manufacturers.
- Model: A string that represents the specific model of the car. The model should be limited to a specific list of models for each manuf... | codefeedback |
Calculate the factorial of a given number n. The factorial of a number is the product of all positive integers from 1 to n. Implement a function that takes an integer n as input and returns the factorial of n. The function should have a time complexity of O(n^2) and a space complexity of O(1). | codefeedback |
Output a regular expression to match all dates in the following format dd/mm/yyyy and also validate the dates for correctness.
In addition to matching the date format, the regex expression should also validate the dates by ensuring that the day and month are within the appropriate ranges (e.g. day: 1-31, month: 1-12),... | codefeedback |
Calculate the area of a triangle with base b and height h using a recursive approach. The base and height are both positive integers greater than 1 and less than 10^5. The output should be rounded to two decimal places. | codefeedback |
Create an HTML form that takes the user's name, email, and photo, and allows the user to select multiple photos to be saved in a database. The form should include validation to ensure that the email address entered is in a valid format and that the photos selected are of the correct file type and size. Additionally, im... | codefeedback |
Please optimize the following C code to find the third minimum element in an array. | codefeedback |
Write a function to check for palindrome
Given a string, the task is to determine whether it is a palindrome or not. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward.
Example:
Input: "abcba"
Output: True
Constraints:
- The input string can contain any ... | codefeedback |
Write a function that receives an array and removes every odd element from it. However, you are not allowed to use any built-in array methods or create a new array. You must modify the original array in place. The array can contain any positive or negative integer, including duplicates. The function must also handle ne... | codefeedback |
Write a program in a programming language of your choice that demonstrates the concept of static variables in a multi-threaded environment. The program should have a class with a static variable and two methods. The first method should increment the static variable by 1, and the second method should print the value of ... | codefeedback |
Create a JavaScript function to get the last K items of an array, where K is a positive integer. The function should also check if the array is empty or if K is larger than the length of the array, and handle these cases appropriately. Additionally, the function should handle arrays that contain nested arrays and retur... | codefeedback |
Write a script for swapping the values of two variables in Ruby without using any temporary variables, the built-in Ruby method for swapping values, or any arithmetic operations. | codefeedback |
Write a code for creating multiple variables with a single statement in Python and assign them with values in a specific pattern.
Example pattern:
- The first variable should be assigned with the value of 1.
- The second variable should be assigned with the value of the first variable squared.
- The third variable sho... | codefeedback |
Given a nested XML structure, parse and extract the value of a specific element, while also checking if the book is available for borrowing.
XML Structure:
<library>
<section id="1">
<category>Programming</category>
<books>
<book id="1" available="yes">
<title>Python fo... | codefeedback |
Develop a query in SQL to display the product name, product price, and the number of units sold from a table named 'products' with a product price greater than 10 and less than 50, and the number of units sold is greater than or equal to 100, ordered by the total sales amount in descending order. | codefeedback |
Create a series of nested for loops in Java to print the prime numbers between 1 and 100 in descending order on separate lines. Additionally, modify the code to skip printing any prime numbers that end with the digit 5. | codefeedback |
Compare and contrast the performance differences between Cython and Python when executing a computationally intensive task. Include a detailed explanation of how each language handles memory management and provide code examples to support your explanation. | codefeedback |
Create a Ruby class for a customer and add attributes for name, age, address, and contact information (phone number and email address). Implement a method that checks if the email address provided is valid, following the standard email address format. The method should return true if the email address is valid and fals... | codefeedback |
Compose a for loop in Java to print the numbers from 4 to 1 on separate lines, but only if the number is divisible by both 2 and 3. Otherwise, print "Skipped: " followed by the number on a new line. Ensure that the loop runs exactly 5 times. | codefeedback |
Create an if-else statement in C++ to check if an integer number is greater than 0. Additionally, the code should also check if the number is a prime number or a perfect square and print out the corresponding message. The code should not use any built-in functions or libraries for prime number or perfect square calcula... | codefeedback |
Write a program in Java to reverse a string without using any additional data structures or built-in functions. The program should modify the given string in-place.
Example:
Input: "hello world"
Output: "dlrow olleh"
Additional Constraints:
- The algorithm should have a time complexity of O(N), where N is the size of... | codefeedback |
Classify a large dataset of text whether it is opinionated or objective, while maintaining a time complexity of O(n) and space complexity of O(1). The dataset may contain sentences in multiple languages, and the classifier should be able to identify the language of each sentence before classifying it as opinionated or ... | codefeedback |
Design a function in JavaScript to take in two strings as parameters and return true if the strings are anagrams and false otherwise. The function should also ignore any leading or trailing white spaces in the strings. Additionally, the function should be case-sensitive, meaning that 'ABC' and 'abc' should not be consi... | codefeedback |
Write code in Python to extract all the unique words from a sentence, remove any punctuation, convert them to lowercase, and store them in a list. The sentence may contain multiple lines and special characters.
"Hello, World! How are you? Are you enjoying your day? I hope you are having a great time. Don't forget to t... | codefeedback |
Implement a tournament bracket for a single elimination tournament using C programming.
You are given a list of players and their corresponding skill levels. Design a program that generates a tournament bracket for a single elimination tournament based on the players' skill levels.
The program should perform the foll... | codefeedback |
Create a script in Bash to navigate to a given directory and list all its contents. Additionally, the script should only list files with a .txt extension and their size should be greater than 1KB. The script should also display the number of lines in each text file, and exclude any hidden files or directories from the ... | codefeedback |
Create an algorithm to traverse a binary tree in post-order, but only for trees that have nodes with three child nodes (a ternary tree) in Python. | codefeedback |
Write a for loop in JavaScript that iterates 1,000,000 times and prints a message each time. However, the loop must start from a random number between 1 and 1000 and increment by a random number between 1 and 100 for each iteration. | codefeedback |
Create a SQL query to sort a table by its numerical contents and then by alphabetical order of the names in case of ties. Additionally, display an extra column showing the rank of each person based on their score.
Table:
+-----------+-----------+
| Name | Score |
+-----------+-----------+
| John | ... | codefeedback |
Write a Python program to determine if an input string is a valid IPv4 address and convert it into its binary representation. | codefeedback |
Given an array of strings, sort them in order of the number of vowels present in each string, with the string having the most vowels appearing first. If two strings have the same number of vowels, then sort them in lexicographically descending order based on the characters present after the first vowel. If a string doe... | codefeedback |
Write a Java program that prompts the user to enter two strings and outputs whether the two strings are anagrams. An anagram is a word or phrase formed by rearranging the letters of another word or phrase.
In addition to the requirements of the given test, you should now also consider the frequency of characters in t... | codefeedback |
Create a web page that contains three input boxes for a user to input their name, age, and gender. Additionally, the web page should include a validation feature that checks if the user's age is between 18 and 65 years old, displays an error message if the age is outside this range, and disables the submit button until... | codefeedback |
Create a dynamic form in HTML containing two input boxes for first name and surname. Upon submitting the form, use JavaScript to validate that the first name and surname are both at least 5 characters long and do not contain any numbers or special characters. If the validation fails, display an error message next to th... | codefeedback |
Write a class in C++ that represents a complex number. Implement operator overloading for addition, subtraction, multiplication, and division of complex numbers. The class should also include member functions to calculate the magnitude and phase of a complex number.
In addition to the original requirements, the comple... | codefeedback |
#Given Test#
Write a function to print the spiral ordering of an input matrix.
[[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 16]]
#Incorrect Code Reference#
Here is a reference piece of code that attempts to solve the problem but contains errors:
def print_spiral(matrix):
result = []
while m... | codefeedback |
Construct a query in SQL to group records by two values and display the count of each group. Additionally, sort the groups in descending order based on the count, and then sort within each group in ascending order based on the other value. | codefeedback |
Create a Python loop that iterates for 1000 times and calculates the sum of all even numbers encountered during each iteration. Ensure that the loop only considers even numbers between 1 and 1000. | codefeedback |
Write an XPATH expression to select an element with a specific id, but only if it is a child of a parent element with a specific class and the element itself has a specific attribute value. | codefeedback |
Construct an HTML form element to define a required input field and validate the input using JavaScript. Additionally, the form should include a password field that requires a minimum length of 8 characters and must contain at least one uppercase letter, one lowercase letter, one digit, and one special character. | codefeedback |
Create a C# class that contains a constructor and two additional methods. The constructor should take two integer arguments and store them as instance variables. The first method should return the sum of the two instance variables. The second method should return the product of the two instance variables. The time comp... | codefeedback |
Create an array in C++ of 10 integers and assign each element to the sum of the previous two elements in the Fibonacci sequence. Additionally, implement a function to calculate the sum of all the elements in the array using recursion. | codefeedback |
Write a python script that takes user input, which must be a positive integer between 1 and 100, and prints out the cubes of the numbers. The script should also check if the input is a valid integer, and if not, prompt the user to re-enter a valid input. The output should be rounded to the nearest whole number. | codefeedback |
Create a Node.js module to return the highest value in a multidimensional array. Each element in the array can either be a number or another array. However, when encountering an array, you must recursively traverse the subarrays to find the highest value. Additionally, you must ignore any negative numbers in the array ... | codefeedback |
Create a sass function to change the text color of a web page, but do not use any built-in sass functions or mixins for this task. Additionally, ensure that the function supports changing the text color of nested elements within a given parent element. Furthermore, the function should also allow for the dynamic adjustm... | codefeedback |
Create and fill a 2-dimensional list with the dimensions n and m, where n and m are positive integers. Each element in the list must be a unique random number between 1 and 100. The sum of all the elements in the list must be greater than 100. Additionally, the sum of each row in the list must be a prime number. n = 3,... | codefeedback |
Create a div in HTML with a background color of 'blue' that is positioned at the center of the page and has a width of 500 pixels and a height of 300 pixels. Additionally, the div should have a border radius of 10 pixels and a text color of 'white'. However, you are not allowed to use any CSS properties or inline style... | codefeedback |
Write a function in Python to return the first n digits of the Fibonacci sequence, where n is a positive integer input from the user.
To solve this problem, you can use the following steps:
1. Start by defining a function called "fibonacci_digits" that takes an integer input "n".
2. Inside the function, initialize an... | codefeedback |
Write a function in Python to iterate over the items in a dictionary and return a list of the keys in reverse order. Additionally, for each key-value pair, concatenate the key and value with a colon in between and append it to the list. The resulting list should be sorted in alphabetical order.
#Incorrect Answer#
def ... | codefeedback |
Create a set in Java from a given array of numbers. The set should only contain unique elements in ascending order. The input array may contain negative numbers as well.
Array: [2, -3, 5, 4, -2, 3, 5, -4]
Time Complexity Requirement: O(n), where n is the number of elements in the input array.
Space Complexity Requirem... | codefeedback |
Given an input array of integers, find and return the two largest unique numbers in the array. If there are multiple occurrences of the largest number, consider only one occurrence in the result. The input array can have both positive and negative numbers.
Example:
Input: numbers = [10, 9, 8, 7, 6, 5]
Output: [10, 9]
... | codefeedback |
Given a string, write a code to find the length of the longest substring that contains exactly three unique characters and print its length.
Example:
Input: "abacabad"
Output: 4
Explanation: The longest substring with exactly three unique characters is "abad", which has a length of 4.
Note:
- The input string can con... | codefeedback |
What is the proper way to check if a variable of type String is empty in Bash, ensuring that the check is case-insensitive and handles leading/trailing whitespace characters correctly? Additionally, you need to ensure that the check is performed in O(1) time complexity. | codefeedback |
Generate a Jupyter notebook to display a scatterplot of a given dataset.
Data: [[5.1, 3.5], [1.4, 2.3], [3.3, 4.3], [3.6, 2.7]]
1. Import the necessary libraries for data manipulation and visualization, including Pandas and Matplotlib.
2. Create a Pandas DataFrame using the given dataset. Each sublist within the datas... | codefeedback |
Under the given dictionary, write a code to replace the value at a given key. The key-value pairs in the dictionary should be sorted in ascending order based on the keys. The code should have a time complexity of O(log n) for the search and replacement operation, where n is the number of key-value pairs in the dictiona... | codefeedback |
Given an integer, calculate the sum of the first n prime numbers, where n is the given integer.
Example:
num = 10
The first 10 prime numbers are 2, 3, 5, 7, 11, 13, 17, 19, 23, and 29.
Therefore, the sum of these prime numbers is 2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 + 29 = 129. | codefeedback |
Create a new list of strings of length greater than 10 from another list, where the new strings must also contain at least one uppercase letter and one special character from the set (!@#$%^&*). The original list should contain at least 5 elements. | codefeedback |
Formulate a MATLAB expression for calculating the sum of the first 1000 natural numbers, but exclude any numbers that are divisible by 3 or 5. Additionally, the program should output the count of numbers that are divisible by both 3 and 5 within the range. | codefeedback |
Write a PostgreSQL query to find the title, rating, and release year of all movies that have a rating above 7.5 and were released in the year 2000, sorted in descending order by their ratings. Additionally, include the genre of each movie in the result. | codefeedback |
Given an array of integers, find the length of the array and the two middle elements. If the array has an odd length, return the middle element. If the array has an even length, return the two middle elements. You should not use any built-in functions or methods to find the middle elements.
However, in addition to not... | codefeedback |
Generate a list of all prime divisors of a given number and calculate the sum of their squares. | codefeedback |
Design a stack class for a language of your choice that supports the following operations:
1. push(value): Adds an element to the top of the stack.
2. pop(): Removes and returns the element from the top of the stack.
3. top(): Returns the element from the top of the stack without removing it.
4. is_empty(): Returns a ... | codefeedback |
Write a program in Python that generates a list of all prime numbers within a given range. The program should take two integers as input, representing the start and end of the range, and should output a list of all prime numbers within that range.
Requirements:
- The program should use the range() function to generate... | codefeedback |
Take the following pandas DataFrame, and convert it to a NumPy array. However, you are not allowed to use the pandas library or any built-in functions for conversion. You must write a custom algorithm to perform the conversion.
The original DataFrame has the following structure:
```
A B C
0 1 4 7
1 2 5 8
2 ... | codefeedback |
Construct a method in Java that takes in an integer as input and returns true if the integer is a prime number, and false otherwise. The method should have a time complexity of O(sqrt(n)). | codefeedback |
Construct a recursive function in C for printing the Fibonacci sequence up to the nth term. The function should have a time complexity of O(2^n). | codefeedback |
Implement a quick sort algorithm for a given array list with the following additional requirements:
1. The algorithm should be implemented using recursion.
2. The algorithm should handle duplicate values in the array list.
3. The algorithm should be implemented to work with any data type, not just integers.
4. The alg... | codefeedback |
Given a list of non-negative integers and a target, write an algorithm to determine if the list contains a subset that sums up to the target. The list may contain duplicate numbers.
You should aim to solve this problem with a time complexity of O(2^n) and a space complexity of O(n).
#Rewritten Test#
Given a list of ... | codefeedback |
Design a shell script for sorting the elements of a given array [2, 5, 1, 8, 4] in descending order. The code provided initially sorts the elements in ascending order. Your task is to modify the code to sort the elements in descending order.
#Hints#
1. Start by understanding the code provided and how it sorts the elem... | codefeedback |
Given a string containing only alphabetic characters and spaces, write a function to reverse the words in the string. The function should ignore any leading or trailing spaces and should also handle multiple consecutive spaces between words.
Additionally, the function should reverse the characters within each word whi... | codefeedback |
Write a code in Python that will take a string as input, split it into words, and return a new string with the words in reverse order. The code should also handle cases where there are multiple spaces between words and should ignore any leading or trailing spaces in the input string. Additionally, the code should handl... | codefeedback |
Write a function that takes in a tuple of strings and converts it into a dictionary, where each string in the tuple is a key and its corresponding index in the tuple is the value. The function should also handle cases where the tuple contains duplicate strings and return a dictionary where each key is unique.
Example:... | codefeedback |
Construct a loop through this string of characters to check for the letter ‘x’. Report what the loop index was when the letter ‘x’ was found. Additionally, you are required to implement the loop using a while loop instead of a for loop. However, you must also handle the case when the letter 'x' is not found in the stri... | codefeedback |
Given an array with both negative and positive numbers, create a function to find the smallest positive number that is a multiple of 3 and greater than 5, inside the array. Additionally, the number must be divisible by 7 and a prime number. If no such number exists, return -1.
int[] array = {-9, -6, -3, 1, 2, 4, 7, 8, ... | codefeedback |
An array of integers is given, write a function to print the second smallest prime number in the array. The function should have a time complexity of O(n), where n is the size of the array. Additionally, the function should not use any extra space other than the variables required for the algorithm. | codefeedback |
Write a code to generate a list of prime numbers from 10 to 20 (inclusive), where the code should be implemented using a recursive function and must not use any built-in library functions to check for prime numbers. | codefeedback |
Write a SQL query that finds the average salary of employees who have worked in the company for at least 5 years and have a salary greater than the average salary of all employees in the "Sales" department. | codefeedback |
Write a SQL query that calculates the average salary for employees in each department, while also excluding any departments where the average salary is below a certain threshold value.
Table: employees
Columns: name, salary, department_id
Additional Constraint: Exclude departments where the average salary is less than... | codefeedback |
Create a code that creates a 3D array of size 5x5x5, where each element of the array is a randomly generated positive integer between 1 and 1000. The sum of all the elements in the array should be calculated and printed as the final output. Additionally, you should implement a function that finds the maximum value in e... | codefeedback |
Write a C++ program for printing the factorial of a given number.
The program should prompt the user to enter an integer greater than 1 and calculate and print the factorial of that number.
If the user enters a negative number or a decimal number, the program should display an error message and prompt the user to enter... | codefeedback |
Recreate a function that sorts the elements of an array using bubble sort. The function should only use a single for loop and must have a time complexity of O(n^2). The input array should contain positive integers only and have a length between 5 and 1000 (inclusive).
In addition to the above requirements, please make... | codefeedback |
Write an SQL query that calculates the total order value for each delivery zone in the ‘zones’ table, considering only the orders that were placed within the last 7 days. Additionally, exclude any orders with an order value less than 10 from the calculation. | codefeedback |
Create a bash script that generates a random 5 letter string with no duplicates in it. The string should consist of only lowercase letters (a-z). Additionally, the script should ensure that the generated string contains at least one vowel and one consonant. | codefeedback |
Create a machine learning model in Python to predict the total surface area of a cube given its side length, density, and temperature. The temperature should be randomly generated within a range of -100 to 100.
side_length = 3
density = 2.5 | codefeedback |
Write a Ruby function that takes an array of integers as input and returns a new array with only unique elements, without using any built-in Ruby methods or data structures. The function should also handle duplicate elements in the array and maintain the order of the original elements.
In addition, the function should... | codefeedback |
In Java, write a program that prompts the user to enter a phrase and then prints the phrase in reverse order, but only if the phrase is a palindrome. If the phrase is not a palindrome, the program should print an error message instead. | codefeedback |
Correct the following C++ code by adding missing syntax and ensure that the value of 'a' is printed when it is equal to 0. Additionally, implement a function that counts the number of occurrences of each unique element in an array and prints them in descending order of their frequency. | codefeedback |
Create a program that takes two inputs, an array of strings and an array of integers. Output an array with the strings at the same indices as the integers. The integers in the second array represent the indices of the strings in the first array that need to be rearranged.
String[] strings = {"cat", "dog", "bird", "fis... | codefeedback |
Create a HTML page that takes two text strings as inputs and outputs the longest one. However, you are not allowed to use any built-in functions or methods to find the longest string. You must implement your own algorithm to determine the longest string. Additionally, you should optimize your algorithm to have a time c... | codefeedback |
Write a JavaScript function that takes a string as input and returns the last four characters of the string, but only if the string contains at least one special character and one uppercase letter. If the string does not meet these requirements, the function should return an error message. | codefeedback |
Write a MySQL query to select all the products that have a price greater than 10, are in stock, and belong to a specific category. | codefeedback |
Create a bash script to create a folder with a given name and its subfolders up to a specified depth. The script should also check if the folder or any of its subfolders already exist before creating them, and provide an error message if they do.
folder_name = my_folder
depth = 3
For example, if the folder_name is "m... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.