instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Build a Python program to generate a prime numbers list in a given range, where the range is from 1 to 10,000,000 and the program should use a multi-threading approach to improve performance. Additionally, the program should include error handling to handle any exceptions that may occur during the execution. | codefeedback |
Using the arrays below, write a function in JavaScript to find the pair of elements from array1 and array2 that have the maximum sum. The function should return the sum of the elements and the indices of the elements in their respective arrays.
array1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
array2 = [11, 12, 13, 14, 15, 16,... | codefeedback |
Apply a modulo operation to each element in an integer array and return the sum of all the resulting values. The modulo operation should be performed using a prime number as the modulo divisor.
## Signature
```python
def modulo_sum(arr: List[int]) -> int:
__input__ : a list arr of n (1 <= n <= 10^5) integers (0 <=... | codefeedback |
Given an array of positive integers, find the smallest positive integer that is divisible by all the numbers in the array.
Example:
Input: [15, 10, 5, 20]
Output: 60
Note:
- The input array will contain at least two numbers.
- All numbers in the input array will be positive integers.
- The solution should be implemen... | codefeedback |
Create a function that rotates a given array by a specific number of positions to the right. The number of positions to rotate should be provided as an input to the function. The function should handle both positive and negative values for the number of positions to rotate.
The time complexity of the function should b... | codefeedback |
Calculate the nth fibonacci number in the series, where n can be as large as 10^9.
Provide a piece of erroneous code as a reference to increase misdirection:
```
def fibonacci(n):
if n <= 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2) + fibonacci(n-3... | codefeedback |
Write a function that transposes a 2D array from column-major format to row-major format. The array is a square matrix where each element is a string representing a binary number. The function should convert each binary number to its corresponding decimal value and transpose the matrix accordingly.
The time complexity... | codefeedback |
Write a HTML page that dynamically sets a random background color for each cell in a table. The background color should be a randomly generated hexadecimal color code in the format '#XXXXXX', where each X represents a random hexadecimal digit (0-9, A-F).
Additionally, the table should have a button that allows the use... | codefeedback |
Create a function that filters out all prime numbers from a given list of integers, numbers, which may contain negative numbers and decimals. The function should handle large input sizes efficiently. You are not allowed to use any built-in functions or libraries to determine whether a number is prime. | codefeedback |
Select the correct answer from the following options to complete the Java code:
int a = 12, b = 6;
int result = __________;
Options:
A) a / b + (b % a);
B) a % b + (b / a);
C) (a + b) / (a - b);
D) (a * b) / (a + b); | codefeedback |
Write a class in Java to convert a decimal number to its binary equivalent. Your implementation should not use any built-in functions or libraries for converting decimal numbers to binary. Additionally, your solution should have a time complexity of O(log n) and a space complexity of O(1). | codefeedback |
Create a program that prints "Hello World" on the screen, but with the following additional requirements:
1. The program should prompt the user to enter their name before printing "Hello World". The program should then print "Hello, [name]" where [name] is the name entered by the user.
2. The program should also disp... | codefeedback |
Modify a given program to replace each element in an array with the product of all elements before it, only using a single loop and without using any additional arrays or data structures. The modified program should have a time complexity of O(n), where n is the length of the input array.
Reference erroneous code:
``... | codefeedback |
Increase the difficulty by adding additional steps and more complex calculations to the original problem.
Create an HTTP request to get the data from the given API and parse it into a JSON object. Then, extract specific fields from the JSON object and perform a series of calculations on the data.
API Endpoint: https:... | codefeedback |
Write an HTML page to display a dynamic table layout that allows users to add, edit, and delete rows. The table should have five columns with headings 'Name', 'Age', 'Occupation', 'Salary', and 'Actions'. The 'Actions' column should contain buttons to edit or delete each row. Additionally, the 'Salary' column should on... | codefeedback |
Create a PHP script to insert values into a table with the following requirements:
1. The table name is 'users' and the fields are username, email, password, registration date, and status.
2. The username field should be limited to a maximum of 20 characters and should not contain any special characters or numbers. Add... | codefeedback |
Design an algorithm to rotate a given array in clockwise direction by a given index, while satisfying the following additional constraints:
1. The algorithm should rotate the array in place, without using any additional memory.
2. The time complexity of the algorithm should be O(n), where n is the length of the array.
... | codefeedback |
Define a function called "calculate_average" that takes a list of integers as input and returns the average of the numbers. The list can have any number of elements.
To solve this problem, follow these steps:
1. Create a function called "calculate_average" that takes a list as input.
2. Initialize a variable called "... | codefeedback |
Write a class in JavaScript that can be used to create an instance of a Date. The class should have the following functionalities:
1. Accept a year, month, day, hour, minute, and second as arguments during instantiation and set them as instance variables.
2. Provide a method to get the current year.
3. Provide a metho... | codefeedback |
Create an algorithm in Python to print the string “welcome” n times, but the number of times the string is printed should be determined by the following conditions:
- If n is even and a multiple of 4, print the string n/3 times.
- If n is odd and a multiple of 7, print the string (n+2)/3 times.
- If n is a multiple of ... | codefeedback |
Write a Python code to check if the given string contains only prime numbers and output the largest prime number found in the string. | codefeedback |
Write a function 'divideList' which takes a list and an integer, and divides the list into n groups. Each group must have a minimum of m elements, where m is an integer greater than 1 and less than or equal to the length of the list divided by n. The elements within each group must be in non-decreasing order.
The func... | codefeedback |
Create a Python function 'checkInteger' that takes a number and returns true if the number is an integer, false otherwise. The function should handle negative numbers as well. The number should be within the range of -10^18 to 10^18.
Additionally, the function should check if the input number is a perfect square and r... | codefeedback |
Create two variables x and y with values 0 and 1 respectively. Then, assign x to y using only the bitwise operators. Additionally, you are not allowed to use any arithmetic operators or assignment operators (such as = or +=) in your solution. | codefeedback |
Create a function in a programming language of your choice that takes an array of integers as input and returns the sum of all the prime numbers in the array. The function should have a time complexity of O(n), where n is the size of the input array. | codefeedback |
Write an `SQL` query to select the employee's name, department, and salary who were hired after `Jan 2020` and have a salary higher than $50,000. Additionally, only include employees whose department has more than 10 employees and whose salary is within the top 10% of salaries within their department. | codefeedback |
Generate a SQL query to retrieve a list of all the movies released in 2019, along with their respective genres and the average rating of each movie. | codefeedback |
Implement a function that can convert a number from a given number system to another, with the additional constraint that the maximum input number is 1000000 and the maximum output number is 1000000000. The function should handle conversions between binary, octal, decimal, and hexadecimal number systems. Input: Convert... | codefeedback |
Write a PHP script to sort an associative array based on its values in descending order and remove any duplicate values. The script should also calculate the sum of all the values in the sorted array. Additionally, the script should handle cases where the values in the array are not all numeric, by excluding non-numeri... | codefeedback |
Write a JavaScript function 'formatDate' which takes a date as a string in the format "YYYYMMDD" and returns it in the format "DD/MM/YYYY". The function should also validate the input to ensure it is a valid date.
Example:
formatDate("20210320") should return "20/03/2021"
Additional requirements:
1. Validate that the... | codefeedback |
Design a C++ function 'removeDuplicates' to remove all duplicate elements from an array and return the new length of the array. The function should also rearrange the elements in the array such that all the unique elements are placed at the beginning of the array, while the duplicate elements are placed at the end. Add... | codefeedback |
Create a `JavaScript` function that takes in two numbers, `start` and `end`, and returns an array containing all the prime numbers between `start` and `end` (inclusive) in ascending order.
The function should have a time complexity of O(n * sqrt(m)), where n is the number of integers between `start` and `end`, and m i... | codefeedback |
Write a function that takes in a list of integers and returns the sum of all the numbers in the list, excluding any numbers that are divisible by both 3 and 5. Additionally, you should handle any errors that may occur during the execution of the function and provide appropriate error messages.
Example:
Input: [32, 15... | codefeedback |
Write a query to find all unique numbers in the column 'quantity' from the database table 'Orders'. Additionally, exclude any negative numbers from the result set. The query should also return the average of the positive numbers and the count of unique positive numbers in the 'quantity' column. | codefeedback |
Write a `Python` program to parse an HTML document, validate the HTML syntax, and store the tags in a list. The program should also remove any duplicate tags and sort the tags in alphabetical order. Additionally, the program should ignore any tags that are nested within other tags.
Provide a piece of erroneous code as... | codefeedback |
Design an algorithm to summarize a long text while ensuring that the summary is grammatically correct, maintains the original context and meaning, and includes a specific set of keywords provided by the user. | codefeedback |
Design a balanced binary search tree that has the following values in the given order and also satisfies the following constraints - 9, 6, 11, 7, 10, 8. The left child of a node should always have a value less than its parent, and the right child should always have a value greater than its parent. Additionally, each no... | codefeedback |
Given a string, create a method to remove all duplicate characters from the string while maintaining the original order of the characters. The string may contain any printable ASCII characters including alphanumeric characters, special characters, and punctuation. The method should also handle multiple occurrences of t... | codefeedback |
What is the minimum number of arguments needed to call the function "foo" where one of the arguments must be a dictionary, another argument must be a list of integers, and the time complexity of the function must be O(n^2)? | codefeedback |
Create a method to find the shortest word in a given array of strings. The method should ignore any words that contain digits, special characters, or vowels. Additionally, the method should handle the case when two or more words have the same shortest length by returning the word that occurs first in the array. | codefeedback |
Write a JavaScript function that takes in an array of strings and returns a new array that meets the following conditions:
1. The strings begin with the letter 'A'.
2. The strings have a length greater than or equal to 5.
3. The strings contain at least two vowels.
Function signature: `function filterArray(arr: string... | codefeedback |
Write an SQL query to retrieve all students from the table "Students" who have scored more than 90 marks, belong to a specific department "Computer Science", and order them by their "grade" in descending order. | codefeedback |
Install Numpy and Matplotlib in Python using pip. After installation, write a Python function that takes in a list of integers and plots a histogram using Matplotlib to show the frequency distribution of the numbers. The x-axis should represent the numbers in the list and the y-axis should represent the frequency. Add ... | codefeedback |
Write a function that takes in a string as input and outputs each character of the string five times, with a comma and space in between each repetition. For example, if the input string is "hello", the output should be "h, h, h, h, h, e, e, e, e, e, l, l, l, l, l, l, l, l, l, l, o, o, o, o, o". The function should have... | codefeedback |
Write a Python function that takes in a list of integers and returns a new list containing only the unique elements, in the order they first appeared in the input list. The function should have a time complexity of O(n) and a space complexity of O(n), where n is the length of the input list.
Additionally, the function... | codefeedback |
Write a SQL query that updates the name of a specified employee in the 'employees' table. The specified employee should have the highest salary among all employees. If there are multiple employees with the same highest salary, choose the one with the lowest employee_id. If there are no employees in the 'employees' tabl... | codefeedback |
Write a Python program that takes in a list of numbers as input. The program should calculate the sum of the numbers in the list and then calculate the average of the numbers. The program should also print the maximum and minimum values in the list. The list should contain at least 10 numbers and cannot contain any neg... | codefeedback |
Write a function to compare two strings and return the number of character positions at which the strings in the two strings differ from each other.
Additional requirements:
1. The function should not be case-sensitive, meaning that uppercase and lowercase characters should be considered equal.
2. The function should ... | codefeedback |
Define a function in Python that takes a positive integer as an argument and returns the sum of the cubes of its digits, but only if the sum is divisible by 7. Otherwise, the function should return the string "Not divisible by 7". | codefeedback |
Implement a function in JavaScript that reads a CSV file and returns an array of objects, where each object represents a row in the file. If any errors occur during the process, the function should throw a custom exception with a descriptive error message. | codefeedback |
Create an object-oriented programming class in Java named "Car" with three private instance variables "make", "speed" and "color". The "make" variable should only accept one of the following values: "Toyota", "Honda", or "Ford". The "speed" variable should only accept positive integer values greater than or equal to 0.... | codefeedback |
Write a program that reads an XML file containing information about employees and prints the attributes present in each 'employee' tag. Additionally, handle the case where the XML file may contain multiple 'employee' tags and print the attributes for each employee.
The XML file will have the following structure:
```
... | codefeedback |
Design a loop in Ruby that prints "Hello World" 1000 times, but with the following modifications:
1. Before printing "Hello World", check if the current index is divisible by 3. If it is, print "Fizz" instead of "Hello World".
2. If the current index is divisible by 5, print "Buzz" instead of "Hello World".
3. If the c... | codefeedback |
Construct a recursive function in JavaScript that calculates the total sum of an array, but with the additional requirements:
1. The function must only use a single loop statement.
2. The function must have a time complexity of O(n), where n is the length of the array.
3. The function must not use any built-in array fu... | codefeedback |
Suggest a highly efficient and industry-standard 3D modelling software specifically designed for creating architectural designs with intricate details, realistic textures, and seamless integration with building information modeling (BIM) software. The software should also support advanced rendering techniques and provi... | codefeedback |
Create a function in Java to take a paragraph as input and return a list of all the unique words in the paragraph, excluding any common stop words such as "a", "the", and "and". The function should also ignore any punctuation marks, consider the sentence to be case insensitive, and handle edge cases such as hyphenated ... | codefeedback |
Compare two strings in C# and return a Boolean indicating whether they are anagrams. The function should ignore any leading or trailing spaces in the strings, consider only lowercase letters, and handle string inputs of up to 10^7 characters. The function should also take into account the frequency of each letter in th... | codefeedback |
Implement a modified version of the quicksort algorithm in Python that sorts a list of integers in descending order. The algorithm should have a time complexity of O(n log n) and should not use any additional data structures or recursion. | codefeedback |
How would you modify the query to print the average grade of the students, only considering grades above 90, and sort the results in descending order based on the average grade?
SELECT name, grade FROM Students WHERE grade > 90 GROUP BY name ORDER BY AVG(grade) DESC; | codefeedback |
Rewrite a MySQL query that prints out the names, grades, and average scores of students from a table. The average score should only include the highest two scores out of the three given scores. Additionally, the query should only consider students who have a grade of A or B. Students (name, grade, score1, score2, score... | codefeedback |
Write a PHP program that takes a multidimensional array as input and prints the contents of the array in a specific format. Each inner array should be printed on a separate line and each element within the inner array should be separated by a comma. The program should also calculate and display the sum of all the eleme... | codefeedback |
Design a function in JavaScript to print all twin prime numbers between 1 to n, where n is a positive integer. Twin prime numbers are a pair of prime numbers that differ by 2, such as (3, 5), (5, 7), (11, 13), etc. | codefeedback |
Build a web service that returns a list of all the customers in a MySQL database, sorted by their total purchase amount in descending order. The service should also allow pagination, with the ability to retrieve a specific page of results based on a given page number and page size.
However, in addition to the original... | codefeedback |
Write a query in PostgreSQL to find the total number of students who have scored above 95% in all subjects and have not missed any classes. Additionally, exclude any students who have been enrolled for less than 1 year. | codefeedback |
Create a program in Java that takes an array with two positive prime numbers as input and prints the result of raising the first number to the power of the second number. The program should handle cases where the input array does not contain two positive prime numbers and display an error message in such cases.
Additi... | codefeedback |
Rewrite the following JavaScript snippet to use nested ternary statements and include an additional condition: if x is greater than 10, set x to 10; if x is less than 0, set x to 0; if x is between 5 and 8 (inclusive), subtract 2 from x; otherwise, add 5 to x.
let x = 10;
x = x > 10 ? 10 : (x < 0 ? 0 : (x >= 5 && x <... | codefeedback |
Create a text box containing the given text and align it to the right side of the screen.
Textbox Text: Welcome to the advanced programming test environment.
Note: The alignment should be done programmatically without using any built-in functions or libraries that handle text alignment. | codefeedback |
Create a program to encrypt or decrypt a given text using a chosen cipher technique.
The Caesar cipher is a substitution cipher where each letter in the plaintext is shifted a certain number of positions down the alphabet. For example, with a shift of 1, A would be replaced by B, B would become C, and so on. The last ... | codefeedback |
Create a C# method to calculate the Nth Fibonacci number, where N is a non-negative integer less than or equal to 100. Additionally, the method should use recursion to solve the problem. | codefeedback |
Write a function in JavaScript that takes a string as input and returns an array of the most frequent words in the string. The function should ignore case sensitivity, remove any leading or trailing punctuation from each word, and exclude common stop words (e.g. "the", "and", "is", etc.) from the word count. The output... | codefeedback |
Create a function that takes as input a string and evaluates its quantity to true if the string contains at least 3 consecutive uppercase letters, regardless of their position in the string. The function should return false if there are no consecutive uppercase letters in the string. | codefeedback |
Create a Node.js server to handle POST requests and store the incoming data in a PostgreSQL database. The server should also implement authentication using JWT and only allow authorized users to access the stored data. Additionally, the server should have a rate limiting mechanism to prevent abuse and ensure fair usage... | codefeedback |
Create a MongoDB document containing the following data:
First Name: John
Last Name: Doe
Age: 32
Occupation: Software Engineer
Email: john.doe@example.com
Address: 123 Main Street
City: Anytown
State: AnyState
Country: AnyCountry
Ensure that the document includes the following additional fields:
- Phone: A string repr... | codefeedback |
Create a SQL query to find the average length of time for all purchases made by customers who have made at least 3 purchases. The result should only include purchases made within the last 6 months. Additionally, exclude any customers who have made a purchase longer than 2 hours in duration. The table structure remains ... | codefeedback |
Find the top 10 customers based on total purchase amount from the "customers" data table, while excluding any customers who have made purchases in the last 30 days. Additionally, the solution should not use any sorting algorithms with a time complexity better than O(n log n) and should use a space complexity of O(1) (i... | codefeedback |
Create a function that takes in a string of characters and returns a new string containing only the characters that are in the even positions of the original string. The function should ignore any non-alphabetic characters and maintain the original order of the characters. For example, if the input string is "A-C-E-G-I... | codefeedback |
Write a program that generates a valid HTML page given the body contents, provided as an input string. The input string can contain any valid HTML elements and tags, and may also include attributes and nested elements. The program should include the necessary doctype declaration and any other required elements to ensur... | codefeedback |
Write a function that takes an array of integers and returns an array of the same length with each element multiplied by 2, while ensuring that the resulting array contains only prime numbers. Additionally, the function should ignore any negative numbers in the input array. [1, 2, -3] | codefeedback |
Generate code for a function that takes a string and returns its reverse, while also ignoring any leading or trailing whitespace characters in the string. Additionally, the function should be case-insensitive, meaning that it should treat uppercase and lowercase characters as equal when reversing the string. The functi... | codefeedback |
Create a C++ class to store data of an employee.
Employee Data: employee_id, name, salary, department
Add the following additional features to the class:
1. Implement a method to calculate the monthly salary after deducting taxes. Assume a progressive tax rate based on the salary brackets:
- 0-5000: 10%
- 5000... | codefeedback |
Convert the following list into a dictionary in Python while ensuring that all keys are unique and values are of type integer. The input list may contain duplicate elements, and your task is to handle these duplicates in the following manner:
- If a duplicate element is encountered, increment its corresponding value i... | codefeedback |
Create a responsive webpage that dynamically generates a random quote from a predefined list and displays it in a centered heading "Welcome". Additionally, implement a button that allows the user to refresh the page to generate a new random quote. The webpage should have a clean and modern design, adhering to the princ... | codefeedback |
Train a machine learning model to predict whether a customer is likely to purchase a product, specifically by considering the customer's historical purchasing behavior, demographics, the interactions they have had with the company's website and mobile app, as well as their social media activity and sentiment analysis o... | codefeedback |
Create a REST API endpoint to retrieve specific user data from the database. The user data should include the user's first name, last name, email, phone number, and address.
The user table in the relational database should now have additional columns for the user's first name, last name, address, and date of birth.
W... | codefeedback |
Create a deep learning model using TensorFlow to predict the probability of rain given an input dataset consisting of various weather parameters such as temperature, humidity, wind speed, and precipitation.
The dataset contains historical weather data for multiple cities and spans several years. Each data entry inclu... | codefeedback |
Sort the given list in descending order according to the sum of all digits in each number. If two numbers have the same sum of digits, then sort them based on the last three digits of the number in ascending order. Additionally, if two numbers have the same sum of digits and the same last three digits, sort them based ... | codefeedback |
Construct a deep learning model using recurrent neural networks to classify a given dataset into three class labels. The dataset consists of 500,000 records with 100 features each. The features are a mix of numerical, categorical, and text data. The class labels are imbalanced, with one class having only 1% of the reco... | codefeedback |
Write a Python program to find the sum of Fibonacci numbers till the number n, where n is a prime number taken as user input. | codefeedback |
Write a program that prompts the user to enter the number of films they want to add to the table. For each film, the program should ask for the film name, release year, and director's name. The program should then display the table with the film names in the first column, release years in the second column, and directo... | codefeedback |
Implement a comparison operator that takes two strings as arguments and returns true if the strings are equal and false otherwise. However, you are not allowed to use any built-in string comparison functions or operators (such as ==, !=, or strcmp). You must come up with your own algorithm to compare the strings charac... | codefeedback |
Create a HQL query to sort records by descending order based on three columns - "age" in descending order, "name" in ascending order, and "salary" in descending order.
Hint: You may need to use additional sorting functions or clauses in your query to achieve the desired result. | codefeedback |
Write a SQL query to select only unique rows from a table that contains duplicate records. Additionally, the query should exclude any rows where a specific column value is less than a certain threshold. | codefeedback |
Take a string consisting of words separated by spaces and remove all the duplicated words within it. The input string will contain only lowercase alphabets and spaces. The length of the string will not exceed 10000 characters. Your solution should have a time complexity of O(n), where n is the length of the string. Add... | codefeedback |
Given a sequence of strings, write a code to check if all the strings in the sequence are unique, contain only lowercase alphabets, and have a length between 3 and 10 characters.
arr = ["cat","dog","mouse"] | codefeedback |
Given a collection of integers, write a code to sort the integers in ascending order. However, you are not allowed to use any built-in sorting functions or libraries. You are also not allowed to use any additional data structures.
arr = [5, 7, 3, 8, 10]
#Difficulty Increased Test# | codefeedback |
What is the Python equivalent of the C++ code snippet, considering that the program should take user input and display the length of the input string, and the program should only use a single line of code? Additionally, the program should be written using lambda functions. | codefeedback |
Write a program that calculates the sum of all prime numbers within a given range of integers from 1 to N. The program should output the sum as the result. | codefeedback |
Write a code to convert a list of comma or semicolon separated strings into a single string, ensuring that the resulting string does not exceed 100 characters in length. The order of the strings should be reversed in the resulting string. The input list can contain a maximum of 20 strings and each string can have a max... | codefeedback |
Please write a program that generates an HTML element with the following requirements:
- The element should be a `<div>` tag.
- Inside the `<div>` tag, display the phrase "Hello, World!".
- The element should have a class attribute set to "hello".
- The element should have an id attribute set to "greeting".
- The eleme... | codefeedback |
Write a Python program to create a modified version of the Caesar Cipher encryption algorithm that includes an additional layer of encryption using a columnar transposition cipher.
In the original Caesar Cipher, each letter in the plaintext is shifted a certain number of positions down the alphabet. In this modified v... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.