instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Sort a given array of integers using Quick Sort and make sure that the algorithm has a time complexity of O(nlogn) in all cases. Additionally, the algorithm should be implemented in a recursive manner and should not use any built-in sorting functions or libraries. | codefeedback |
How is artificial intelligence (AI) used in high-frequency trading in finance to optimize trading strategies and increase profitability while adhering to regulatory constraints and market volatility? Provide specific examples and discuss the potential risks, limitations, and ethical considerations associated with the u... | codefeedback |
How would you design and implement a spell-checker that can handle multiple languages and suggest appropriate corrections based on the context of the misspelled word? Additionally, please provide a code snippet showcasing the implementation of a language model for context-based corrections. | codefeedback |
Write a function that takes in a max number and a step size, and returns the sum of all even numbers between 0 and the max number, inclusive, where each even number is incremented by the step size. | codefeedback |
Edit this code to print out the square of each number from 1 to a given input number, using '#' as a marker. However, the code should only use a single loop and must not use any built-in functions for calculating the square of a number.
Input: 7
Output:
1 #
4 ##
9 ###
16 ####
25 #####
36 ######
49 ####### | codefeedback |
Find the angle between two given vectors in a three-dimensional space. The time complexity of your solution should be O(1) and you should not use any trigonometric functions.
Additional Requirements:
1. Implement the solution using only basic mathematical operations such as addition, subtraction, multiplication, and d... | codefeedback |
Explain the importance of indexing in databases and provide a detailed example of how indexing can optimize query performance, specifically focusing on the use of bitmap indexes for a large dataset. | codefeedback |
What is the difference between static binding and dynamic binding in object-oriented programming? Provide an example of each and explain the advantages and disadvantages of using each binding method. Additionally, explain how dynamic binding can be achieved using virtual functions in C++. | codefeedback |
Implement a function that takes in an array of integers and prints out each element in the array. However, the function should only print out the element if it is a prime number and the sum of its digits is also a prime number.
let nums = [12, 23, 34, 45, 56, 67, 78, 89, 90, 101]; | codefeedback |
Explain the concept of backpropagation in neural networks and its significance in improving the model's accuracy. Additionally, demonstrate the implementation of a neural network model using Python's TensorFlow library to solve a specific problem in the field of image classification.
You are required to build a neural... | codefeedback |
Create a SQL query to find all records of employees who are over 40 years old, have a salary greater than $50,000, and have worked at least 5 years in the company. | codefeedback |
Explain the various data structures that can be used to store a matrix in Python. Compare and contrast these data structures, highlighting their advantages and disadvantages in terms of memory usage, time complexity for common operations, and ease of implementation. Additionally, provide an example of how each data str... | codefeedback |
How can you use recurrent neural networks with long short-term memory (LSTM) units for sequence prediction in natural language processing tasks, such as language modeling or machine translation? Explain the architecture and training process of an LSTM-based RNN, and discuss how it overcomes the vanishing gradient probl... | codefeedback |
Create a Python program that generates an array of size N, where N is a randomly generated number between 1 and 100. The array should contain unique values, and each value should be a randomly generated number between -100 and 100. The program should then sort the array in ascending order and calculate the sum of all t... | codefeedback |
Write a SELECT query to identify the names of authors who have published books with the topic ‘Artificial Intelligence’ and have at least 3 books published in total. Additionally, include the total number of books each author has published and the average rating of all their books. Sort the result in descending order b... | codefeedback |
Create a virtual environment in Python using only built-in modules and without using any third-party tools or libraries. Ensure that the virtual environment allows for the installation of additional Python packages and provides isolation for each project. | codefeedback |
Write code to calculate the total number of votes for a candidate in an election, but only consider the votes from registered voters who are aged 18-30. The age of each registered voter is stored in a separate list called "ages" in the same order as the votes. Only include the votes for candidates who have at least 100... | codefeedback |
Write a code snippet to find all the Pythagorean triplets whose sum of the squares of the three numbers is equal to the given number. The code should have a time complexity of O(n^3) and a space complexity of O(n).
Note: The input number will be a positive integer greater than 0.
Example:
Input: 100
Output: [(3, 4, 5... | codefeedback |
Implement a search engine using recursion that returns all the words from a given list that contain a specific prefix. The search engine should be case-insensitive and should handle both single-word and multi-word queries.
Example:
query = "comp"
data = ["mobile","computer","laptop","tablet"]
Output: ["computer","lapt... | codefeedback |
Write a SQL query to output the full names from a 'persons' table, where the full names are formatted as 'Last Name, First Name'. Additionally, only include persons whose last name starts with the letter 'S' and whose first name contains at least one vowel. | codefeedback |
Create a function in JavaScript to take a given number and subtract 10 from it. However, you are not allowed to use any arithmetic operators (+, -, *, /, %) or the decrement operator (--). The function should only use bitwise operators and logical operators. The time complexity of the function should be O(1) and the sp... | codefeedback |
Design a program to find all prime numbers up to a given limit n. Additionally, for each prime number found, the program should determine and display the sum of its prime factors. | codefeedback |
Convert the following array of strings to a set of tuples in Python. Each tuple should contain the string from the original array along with its length and the number of vowels it contains. However, vowels should only include the letters 'a', 'e', 'i', 'o', and 'u'. Additionally, the tuples should be sorted in descendi... | codefeedback |
Make an API call to get the current weather in a given city. Implement rate limiting functionality to restrict the number of API calls to a maximum of 10 per minute. Additionally, create a caching mechanism that stores the weather data for each city for a maximum of 5 minutes, after which the data should be updated by ... | codefeedback |
Create a random list of 10 prime numbers in the range of 100 to 1000 in Python, ensuring that all numbers in the list are unique and sorted in ascending order. | codefeedback |
Write a program in Java to print the first n terms of the Fibonacci sequence using a recursive approach. Additionally, implement a memoization technique to optimize the recursive solution. | codefeedback |
Write a function in C++ to check if the given array of integers is in ascending order and contains only prime numbers. The array may contain duplicate elements. | codefeedback |
Identify the wrong code in this JavaScript snippet.
let a = "Hello World!";
console.log(a);
console.log(b);
console.log(c);
#Reasoning#
In the rewritten test, two additional incorrect code lines `console.log(b);` and `console.log(c);` are added. This requires the test taker to not only identify the original incorrect ... | codefeedback |
Generate a JavaScript object that contains three key-value pairs. The keys must be unique and alphanumeric strings of length between 8 and 12 characters. The values must be either integers between 1 and 100 or strings consisting of only lowercase alphabets. Additionally, one of the values must be an array containing at... | codefeedback |
Implement a custom machine learning algorithm in Python to make predictions on a given dataset. Additionally, handle missing values in the dataset by using an appropriate imputation technique. | codefeedback |
Write a Java class to define a student object that includes a name, grade, and a list of subjects they are enrolled in. Each subject should have a name, a corresponding grade for that subject, and a maximum grade that can be achieved. The class should have methods to add a subject and its grade, calculate the average g... | codefeedback |
Write a C program to calculate the factorial of a number using recursion and only using bitwise operations.
The factorial of a number is the product of all positive integers less than or equal to the number. For example, the factorial of 5 is 5 * 4 * 3 * 2 * 1 = 1 | codefeedback |
Modify the code below to create a new function called "addSquares()" that adds the squares of two numbers and returns the result. The function should only accept positive integers as input and throw an error message if any other data type or negative integers are passed as arguments.
```python
def addSquares(a, b):
... | codefeedback |
Convert the string "Hello World" to upper case using a Java program. Ensure that the program can handle strings containing special characters and digits, and the converted string should be sorted in reverse alphabetical order. Additionally, the program should remove any duplicate characters from the converted string be... | codefeedback |
Write an Apache VTL code to check if the user is logged in or not. Additionally, implement a feature that checks if the user is an administrator and display a specific message if they are. The code should handle concurrent user sessions and log the user out after a specific period of inactivity. | codefeedback |
Given an array of integers, find the second largest number and its frequency. If there are multiple numbers with the same frequency, return the smallest number among them. You are not allowed to use any built-in sorting functions or data structures.
Example:
Input: [13, 54, 78, 54, 3, 87]
Output: Second largest number... | codefeedback |
Write a C++ program that counts the number of parameters in a function declaration. The program should prompt the user to enter the function declaration, and then output the total number of parameters in the function. The program should handle function declarations with up to 10 parameters.
Additionally, modify the pr... | codefeedback |
Modify a C++ program to print the following sequence of numbers using a loop:
* 200, 195, 190, 185, 180, 175, 170, 165, 160, 155, 150, 145, 140, 135, 130, 125, 120, 115, 110, 105, 100, 95, 90, 85, 80, 75, 70, 65, 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0 | codefeedback |
Craft a JavaScript snippet to create an array with elements from 0 to 100, but only include the prime numbers. | codefeedback |
Create a python script to determine whether a given number is prime or not. Your solution should also calculate the sum of all the prime numbers less than the given number. Additionally, your program should display the prime factors of the number if it is not prime. | codefeedback |
Write a MySQL query to display the region with the highest population count. The query should only include regions that have a population count greater than 1 million. Additionally, you need to exclude regions that have a population count less than 10 million. | codefeedback |
Find the maximum element from a given array in JavaScript.
Given an array of integers, you need to find the maximum element in the array and return it. If the array is empty, you should return undefined.
Additionally, you need to handle the case where the array contains duplicate maximum elements. In such cases, you ... | codefeedback |
Compute the maximum amount of money X which can be obtained using three given coins of denomination A, B, and C, where A, B, and C are prime numbers. Find the minimum number of coins required to make a sum of X, considering that you can use each coin multiple times.
A = 5
B = 7
C = 11
X = 120 | codefeedback |
Write an SQL query to identify the most frequently occurring value in a given column. Your solution should also exclude any values that occur less than X times, where X is a positive integer input parameter to the query. Additionally, you should only consider the most frequently occurring value if it is greater than Y ... | codefeedback |
Create a PHP script that encodes a given string in base-64 and then performs a reverse operation to decode the encoded string back to its original form. The script should also validate that the original string contains at least 10 alphanumeric characters before encoding it. | codefeedback |
Create a C++ program for printing a pyramid pattern up to a given number n, where n is an odd number greater than or equal to 5. The pyramid pattern should be constructed using a recursive function.
The pyramid pattern should be printed in the following format:
*
***
*****
*******
******... | codefeedback |
Write a MongoDB query to find documents where a given field contains a substring, but exclude any documents where the substring appears within a specified nested field. Additionally, the query should only consider documents that have a specific value in another field and must be sorted in descending order based on a di... | codefeedback |
Create a program in Java to print a multiplication table of size N x M, where N and M are positive integers. The program should take the values of N and M as input from the user.
The program should include error handling to ensure that the values of N and M are within a certain range (e.g., between 1 and 100). If the... | codefeedback |
Implement a comparator method in Java to compare two objects of the same class. The comparison should be based on the country's population and area, with population taking priority. Additionally, the comparison should be case-insensitive for the country's name. The comparator should return a negative integer if the fir... | codefeedback |
Compile and execute this Java code. This code should prompt the user to enter their name and age. It should then print a personalized message based on the following conditions:
- If the user is under 18 years old, the message should say "Hello [Name], you are too young to proceed."
- If the user is between 18 and 65 y... | codefeedback |
Create a SQL query to find the highest grossing movie, excluding movies that have a box office gross less than $1 million and were released before 2010.
Table Name: "Movies"
Columns: "MovieName", "BoxOfficeGross", "ReleaseYear" | codefeedback |
Create a function to register a new user using a given username, email, and password. The username must be unique and contain only alphanumeric characters. The email must be a valid email address, should not already be registered in the system, and should not be a disposable email address. The password must be at least... | codefeedback |
Edit the following function to only accept lowercase parameters and return the reversed name. The function should also remove any vowels from the reversed name before returning it.
def greeting(name):
vowels = ['a', 'e', 'i', 'o', 'u']
if not name.islower():
raise ValueError("Name must be in lower... | codefeedback |
Create a function that groups a given set of numbers into continuous ranges. A continuous range is defined as a sequence of numbers where each number is exactly one greater than the previous number. Additionally, the function should return the sum of each range.
Example:
Input: [1, 3, 4, 6, 7, 8, 10]
Output: [[1, 1],... | codefeedback |
Write a SQL query to calculate the total rental fees for customers who have rented a movie in the past 30 days, grouping the results by month, customer, and movie category. Additionally, exclude any customers who have rented less than 3 movies in the past 30 days.
Table Name: "Rentals"
Columns: "CustomerId", "RentalD... | codefeedback |
Implement a function that takes in a list of integers and returns a new list with each integer multiplied by 2. However, the function should meet the following additional requirements:
1. The function should use a generator instead of returning a new list. It should yield each multiplied integer one at a time, rather ... | codefeedback |
Write an SQL query that returns the sum of inventories in the Inventory table, but only for items that have a quantity greater than 100 and a price per unit greater than $10. | codefeedback |
Implement a program that calculates the sum of all prime numbers from 1 to a given positive integer, excluding the number itself. The program should use 'break' and 'continue' statements in a for loop to efficiently skip non-prime numbers and terminate the loop when the desired sum is reached. The program should also t... | codefeedback |
Create a function that converts an arbitrary number from any base between 2 and 16 to its decimal representation, without using any built-in conversion functions or libraries. The function should be able to handle numbers with up to 100 digits. Additionally, the function should handle negative numbers in the input and ... | codefeedback |
Create an SQL query that returns the top five most expensive items in the table, but exclude any items that have been discontinued. Additionally, the query should also display the number of times each item has been ordered in descending order. | codefeedback |
Create classes and interfaces to represent an online news system.
The system should have the following features:
1. Users should be able to register and log in to the system using two-factor authentication.
2. Users should be able to view a list of news articles sorted by popularity.
3. Users should be able to search... | codefeedback |
Write a function in JavaScript to check if the given string contains at least three consecutive vowels or not. | codefeedback |
Create a Ruby script to loop through the items of a given array and print it on the command line. However, you should only print the items that start with a vowel. Additionally, the script should convert all the vowels to uppercase before printing. The given array will contain strings consisting of only lowercase alpha... | codefeedback |
Given an array of numbers and a target number, write a program to check if the target number exists in the array. Output true if it exists and false if it does not. If the target number exists in the array, output its index position in the array. If the target number exists multiple times in the array, output the index... | codefeedback |
Design a data structure that will store name, phone number, address, email, age, and occupation of a person. Additionally, the data structure should have the following functionalities:
1. Add a person to the data structure.
2. Remove a person from the data structure.
3. Update the details of a person.
4. Search for a ... | codefeedback |
Design a logo with a complex and dynamic animated effect, using advanced CSS and JavaScript techniques. Write the code to display the logo on a webpage, ensuring that the animation runs smoothly and efficiently. | codefeedback |
Write a Python function that checks if a given string is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward, disregarding spaces, punctuation, and capitalization. Your function should return True if the input string is a palindrome and False ot... | codefeedback |
You receive an array of numbers as input and you need to calculate the median number. However, you are not allowed to use any built-in functions or libraries to sort the array. The input array may contain both odd and even number of elements. Additionally, the array may contain duplicates and negative numbers. | codefeedback |
You need to write a function that validates a given password. It should only be valid if it contains at least one lowercase letter, one uppercase letter, one number, and one special character. Additionally, the password should be at least 8 characters long and should not contain any consecutive repeating characters. Th... | codefeedback |
Convert the given list of integers to a string of comma separated values, ensuring that all even numbers are doubled and all odd numbers are squared. The resulting string should be reversed and each value should be enclosed in parentheses. The output should only include values that are greater than 10.
[1, 2, 3, 4, 5] | codefeedback |
Using only HTML and CSS, create a responsive webpage layout with the following specifications:
- The webpage should have a navigation bar at the top, containing links to Home, About, and Contact pages. The navigation bar should be fixed to the top of the screen.
- Below the navigation bar, there should be a full-width ... | codefeedback |
Write a Java program to insert a new node at a specified position in a circular linked list. The position should be provided as input by the user.
Additional Requirements:
1. The program should handle the case where the specified position is out of bounds (i.e., greater than the length of the list or negative) by eith... | codefeedback |
Explain the concept of color models in web development and specifically focus on the HSL color model. Discuss the advantages and disadvantages of using the HSL color model compared to other color models, such as RGB and CMYK. Provide examples of how the HSL color model can be implemented in web design, including the us... | codefeedback |
Create a data structure to store records of students' attendance with the following constraints: each record should include the student's name, ID, date and time of attendance, and attendance status (present, absent, late). The data structure should also be able to handle multiple records for each student and provide f... | codefeedback |
Devise a data structure to store an inventory of items in a store. Additionally, implement a method that allows the user to add an item to the inventory, considering that each item has a unique identifier. The method should handle the scenario where the user tries to add an item with an identifier that already exists i... | codefeedback |
Create a code to print the items from a given array in reverse without using any built-in functions or methods for reversing an array. The code should only use logical steps and operations to achieve the desired result. Additionally, the code should have a time complexity of O(n), where n is the length of the array.
N... | codefeedback |
Create a PHP script that performs the following tasks:
1. Establish a connection to a MySQL database by taking the database credentials as input from the user.
2. Prompt the user to enter the name of a table in the database.
3. Execute a query to retrieve a set of data from the specified table.
4. Fetch and display th... | codefeedback |
Create a code to raise a number to a given power p, using only basic arithmetic operations (addition, subtraction, multiplication, and division) and without using any built-in exponentiation functions or operators. The code should also handle negative values for both the base and the power, and return the result as a f... | codefeedback |
Write a function that takes in a list of strings and returns True if any of the strings contains the letter `a`. Additionally, the function should ignore any strings that start with a lowercase letter. The function should have a time complexity of O(n), where n is the total number of characters in all the strings in th... | codefeedback |
Refactor the following condition to use the ternary operator instead of an if-else statement, and add the requirement that the solution must be written in a single line of code. Additionally, introduce a new variable "z" that should be assigned the value of 2 if "x" is equal to 0, and 3 if "x" is greater than 0.
y = (... | codefeedback |
Given a two-dimensional array, write a code to print the elements column-wise. The array may contain duplicate elements. Your code should also handle the case when the array is empty and return an appropriate message. Additionally, you need to handle the case when the array is not a perfect rectangle (i.e., each row do... | codefeedback |
Write a JavaScript function to convert a given decimal number to its Roman numeral equivalent. The decimal number will be within the range of 1 to 3999.
You may not use any built-in functions or libraries to convert the decimal number to a Roman numeral. Instead, you must manually implement the conversion algorithm.
... | codefeedback |
Create a bash script to check the disk usage of the "/tmp" directory and display the top 10 largest subdirectories within it. Additionally, exclude any subdirectories that are empty from the final list of largest subdirectories. | codefeedback |
Create a MongoDB query to find all documents that have an array "items" with a field "name" equal to "pen" and a field "quantity" greater than or equal to 10. Additionally, the query should only include documents where the "price" field is less than or equal to 5 and the "color" field is either "blue" or "red". | codefeedback |
Create a PHP function that sorts the elements of an array in ascending order using the bubble sort algorithm. Additionally, handle the case where the array may contain duplicate elements, ensuring that they are properly sorted. | codefeedback |
Reverse a given array without using a loop. The solution must have a time complexity of O(1) and must not use any built-in array manipulation functions such as reverse(). Additionally, you are not allowed to create a new array to store the reversed elements. The original array must be modified in-place. The array can c... | codefeedback |
Filter the array based on the following condition: only include elements that are prime numbers and greater than 2. Return a new array of elements that satisfy the condition. The implementation should have a time complexity of O(n) and should not use any built-in functions or libraries that directly check for prime num... | codefeedback |
Create a responsive CSS class for a table to be displayed on a mobile device that should have alternating row colors, a fixed header, the ability to sort columns by clicking on the headers, and also include a feature to filter the table data based on user input. | codefeedback |
Given a list of strings, write a program to format each string such that only the first letter of each word is capitalized. The solution should have a time complexity of O(n) and a space complexity of O(1).
Example:
Input: ["Hello world", "Wonderful DAY", "this is a test"]
Output: ["Hello World", "Wonderful Day", "Thi... | codefeedback |
Suggest an efficient algorithm to search for a target element in a binary search tree in less than O(log n) time, while also ensuring that the target element is stored at the deepest level of the tree. | codefeedback |
Write a MySQL query to insert values into a table called 'users' with three columns: 'name', 'email', and 'age'.
name: John, email: john@example.com, age: 28
Additional Requirements:
1. The 'name' column should only accept values that are between 2 and 50 characters inclusively.
2. The 'email' column should only accep... | codefeedback |
You are given an array of integers. Find the maximum sum of any subarray of the given array, where the subarray must have a length of at least 3 and contain only positive integers. If no such subarray exists, return 0. | codefeedback |
Write a function to calculate the average value of the values stored in a nested dictionary using a recursive approach. The nested dictionary can have an arbitrary number of levels.
For example, given the following nested dictionary:
mydict = {'a': {'x': 1, 'y': 2}, 'b': {'z': 3}, 'c': 4}
The function should return t... | codefeedback |
Design a function in Python to sort a list of tuples based on the first element in descending order, while ignoring the cases of the first element. The function should handle both integer and string values in the tuples. Additionally, the function should handle tuples with more than two elements and sort the list of tu... | codefeedback |
Describe a machine learning algorithm that uses supervised learning and has a requirement of achieving a minimum accuracy of 95% on both the training data and the testing data. Additionally, discuss the steps you would take to handle overfitting and underfitting in this algorithm. | codefeedback |
Create a React component which renders an input box and a submit button. When the user enters a valid email address into the input box and clicks the submit button, display a success message below the input box. If the user enters an invalid email address, display an error message instead. Additionally, implement a cha... | codefeedback |
Create a Swift class with a method named 'validate' which takes in an array of integers and returns a new array containing only the prime numbers from the input array.
Note: A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The method should only consider positive... | codefeedback |
Design an algorithm to check if two given binary trees are identical, where each node contains an integer value, a character value, and a timestamp value. The algorithm should also compare the character values of the corresponding nodes and return true only if both the integer values, character values, and timestamps a... | codefeedback |
Write a Java program to remove comments from the Java program. However, your program should also handle nested comments properly.
Erroneous code:
public class HelloWorld {
/*
This is a multiline comment.
*/
/* public static void main(String[] args) {
System.out.println("Hello World!"); // This ... | codefeedback |
Use Java to generate a string containing 10000 random characters of length 100, ensuring that each character in the string is unique. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.