instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Create a Java program that reads two positive prime numbers from the user and prints the sum of their prime factors. | codefeedback |
Write a recursive function in Java to print all the numbers in a given list in reverse order.
int[] list = {21, 34, 54, 77, 92}; | codefeedback |
Write a C++ program to print all prime numbers between 1 and 1000, using a multi-threaded approach where each thread checks a range of numbers for primality. | codefeedback |
Create a Python program to extract all unique words from a given sentence, while also counting the frequency of each word. This sentence may contain punctuation marks and may have words in different cases (uppercase and lowercase) that should be considered as the same word. Additionally, exclude common stop words such ... | codefeedback |
Suggest a data structure to store the following data for an online grocery store:
- Names of fruits and vegetables
- Quantity available for each item
- Price per unit for each item
- Nutritional information for each item, such as calories, carbohydrates, and vitamins | codefeedback |
Create a responsive HTML page that displays the words "Hello, World!" in different colors and fonts. The page should also include a button that, when clicked, changes the background color of the page randomly. Additionally, the text "Hello, World!" should be animated to fade in and out continuously. The font size of th... | codefeedback |
Write a function in Python that takes in two strings and concatenates them together with a space in between. The function should also reverse the order of the characters in the concatenated string. | codefeedback |
Write a SQL query that finds, in a table of employees, the names, titles, and salaries of all employees who work in the Marketing department and have a salary greater than $50,000.
Table: Employees
| EmployeeID | Name | Department | Title | Salary |
|------------|------|--------------|-----------... | codefeedback |
Write a CSS style to add a yellow background to the body of a webpage only when the viewport width is greater than 600 pixels and the user has scrolled down more than 50% of the page. | codefeedback |
Write a function that takes a string and returns a dictionary counting each unique character in the string. The function should only count alphabetical characters and ignore any non-alphabetical characters. The returned dictionary should be sorted in descending order based on the count of each character.
#Example:
In... | codefeedback |
Generate a list of 10 random lowercase letters. | codefeedback |
Write a function in Java to sort a given array of numbers into ascending order using a merge sort algorithm. The function should have the following signature:
void mergeSort(int[] array, int low, int high)
The function should sort the elements in the array from index low to index high (inclusive) using the merge sort ... | codefeedback |
Read the input text and reverse it character by character, taking into account only alphanumeric characters and ignoring any punctuation or special characters. This is a sample text. | codefeedback |
Given a string in snake_case, convert it to camelCase.
Example:
Input: this_string_should_be_converted_to_camelCase
Output: thisStringShouldBeConvertedToCamelCase
Additional Constraints:
- The input string will only contain lowercase alphabets and underscores.
- The input string will not be empty.
- The first charact... | codefeedback |
Suggest a sorting algorithm to sort the following array in descending order. The algorithm should have a time complexity of O(nlogn) and must be implemented using recursion. Additionally, the sorted array should be stored in a new array and the original array should remain unchanged. arr = [17, 21, 4, 7, 29, 34, 11] | codefeedback |
Write a bash script to list the content of the current directory. The script should only display files with a .txt extension and sort them in descending order based on the file size. The output should include the file name, size, and last modified date. | codefeedback |
Create a Python function that takes in a string as input and returns a dictionary where the keys are the unique characters in the string and the values are lists containing the indices of each occurrence of the character in the string.
Example:
Input: "hello"
Output: {'h': [0], 'e': [1], 'l': [2, 3], 'o': [4]}
The fu... | codefeedback |
In C++, search a given string for a given sub-string and return the starting index of each occurrence.
string = "This is a string and this string is very interesting"
sub_string = "string"
Time Complexity: O(n*m), where n is the length of the string and m is the length of the sub-string.
Space Complexity: O(1) | codefeedback |
Generate a 10-element tuple of random prime numbers between 50 and 100 using Python. | codefeedback |
Generate an array of prime numbers up to and including the number | codefeedback |
Create a Python program to generate a random string of 5 characters. The program should ensure that the string contains at least one uppercase letter, one lowercase letter, one digit, and one special character. | codefeedback |
Suggest a syntax to create a PHP class for a user that includes the following functionality:
1. Implement a constructor that takes in parameters for the user's name, email, and password.
2. Add a method to validate the email format of the user.
3. Implement a method to generate a unique username for the user based on t... | codefeedback |
Manipulate the given list in Python to include the new element at the beginning. However, you are not allowed to use any built-in list manipulation methods or functions such as `insert()` or `append()`.
list = [1, 2, 3]
new_element = 0 | codefeedback |
Calculate the result of raising 2 to the power of n, where n is an integer between 1 and 1000. | codefeedback |
Write a function in Python to check if two strings are an anagram or not, but without using any built-in string manipulation methods or libraries. | codefeedback |
Write a query in SQL to list the employee information from the given Employee table in descending order of their salaries, but exclude any employees whose salary is below a certain threshold set by the user. The user should be prompted to input the threshold value before executing the query.
Table structure:
Employee_... | codefeedback |
Write a SQL query to select the row with the customer id "CID001" from the customers table, but exclude any rows where the customer's status is "Inactive". | codefeedback |
Find the average salary of the given table, but only for employees who have been with the company for at least 5 years and are part of the Finance department.
Table structure:
Employee_ID Name Department Salary Date_of_Joining | codefeedback |
Write a JavaScript code snippet to center text in a div element with id "myDiv" using only pure CSS (no JavaScript allowed). | codefeedback |
Identify the most efficient data structure to store a list of strings, while minimizing the time complexity for searching for a specific string within the list. Additionally, propose an algorithm to sort the list of strings in descending order of their lengths, while minimizing the space complexity. | codefeedback |
Write a JavaScript code to add two numbers using a prompt, but instead of adding two numbers directly, create a function that takes in two numbers as parameters and returns their sum. Also, add input validation to ensure that the user can only input valid numbers. | codefeedback |
Create a dictionary of fruits and their respective colors. Each fruit can have multiple colors associated with it. Ensure that the dictionary supports fast retrieval of fruits based on their colors. Additionally, implement a method to efficiently find the fruits that have the most number of colors associated with them. | codefeedback |
Implement a doubly linked list in Python. | codefeedback |
Explain what a Turing machine is and provide a detailed description of how it can be used to solve a specific computational problem. | codefeedback |
Compare the performance of Grover's algorithm, classical search algorithms, and quantum search algorithms on a dataset of size N. Analyze the time complexity and space complexity of each algorithm and discuss their advantages and disadvantages in terms of runtime and memory usage. Additionally, consider the impact of q... | codefeedback |
Write an SQL query to select the names and ages of all employees from the table 'employees' who are currently employed and have an age greater than 25. Additionally, order the results in descending order based on their ages and limit the output to only display the top 10 oldest employees. | codefeedback |
Write a C++ program that implements a Stack data structure using only linked lists. The program should include the following functionalities:
- Push: Add an element to the top of the stack.
- Pop: Remove and return the top element from the stack.
- Peek: Return the top element without removing it from the stack.
- isEm... | codefeedback |
Edit the following JavaScript code to reverse the characters of a given string. The code should not use any built-in string reversal functions or methods. | codefeedback |
Design a class in Java that can store student information, including their first name, last name, date of birth, and a list of courses they are enrolled in. The class should also provide methods to add a new course, remove a course, and calculate the student's age. Additionally, the class should have a method to return... | codefeedback |
Implement a function that validates and formats the following JSON data based on a specific schema:
{
"name": "John",
"age": 20,
"address": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"country": "USA"
},
"contact": {
"email": "john@example.co... | codefeedback |
Create a class to represent a two-dimensional vector. Implement the following methods:
1. `__init__(self, x: float, y: float)`: Initialize the vector with the given x and y coordinates.
2. `get_x(self) -> float`: Return the x-coordinate of the vector.
3. `get_y(self) -> float`: Return the y-coordinate of the vector.... | codefeedback |
Create an array that contains only prime numbers from 0 to 100 in JavaScript. | codefeedback |
Create a class in Java that can store a list of students, their courses, and their corresponding grades. Additionally, implement methods to calculate the average grade for each student and for each course. | codefeedback |
Design a class in Java that can store a list of books and their associated authors. The class should also have the following functionality:
1. Add a book to the list with its author(s).
2. Remove a book from the list.
3. Search for a book by its title and return its author(s).
4. Search for a book by its author and ret... | codefeedback |
Write a recursive function that calculates the factorial of a given number in Python. The function should handle negative numbers as well. | codefeedback |
Create a script that sorts the given array in decreasing order, using only recursion and without using any built-in sorting functions or loops. The array may contain duplicate elements. The script should have a time complexity of O(nlogn) and a space complexity of O(logn). | codefeedback |
Write a script for finding the largest number in the given array and its corresponding index. If multiple numbers have the same maximum value, return the index of the first occurrence.
const array = [4, 8, 2, 6, 9, 3]
#Difficulty Increased Test# | codefeedback |
Create an MySQL table with four columns: "id", "name", "age", and "city". The "id" column should be the primary key and auto-increment. The "name" column should be a non-null string of maximum length 50 characters. The "age" column should be a non-null integer between 1 and 100. The "city" column should be a non-null s... | codefeedback |
Create an HTML form with three text fields—name, age and gender. Upon submitting the form, validate the inputs and display appropriate error messages if any of the following conditions are not met:
1. The name field cannot be empty and should contain only alphabetic characters.
2. The age field cannot be empty and shou... | codefeedback |
Write JavaScript to swap the first and last elements in an array. The array should contain at least 5 elements.
array = [10, 20, 30, 40, 50, 60] | codefeedback |
Classify a collection of articles as spam or ham.
Given a collection of articles, you are required to classify each article as spam or ham. The input is a list of strings where each string represents an article. Your task is to implement a function that takes in this list and returns a list of classifications, indicati... | codefeedback |
Write Python code to generate a random password of 12 alphanumeric characters, ensuring that it contains at least one uppercase letter, one lowercase letter, and one special character. | codefeedback |
Write a method that prints out all the prime numbers between 1 and 1,000,000. | codefeedback |
Implement a method in JavaScript that checks if a String is a palindrome. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. The method should return true if the String is a palindrome and false otherwise. The method should ignore any non-alphanumeric chara... | codefeedback |
Write a Java method that takes a string and prints out the number of occurrences of each unique vowel in the string. Ignore case sensitivity.
String = "adda123de3f" | codefeedback |
Implement a custom ArrayList class in Java without using any built-in data structures or collections libraries. The custom ArrayList should have the following methods:
- add(element): adds the specified element to the end of the list
- remove(index): removes the element at the specified index from the list
- get(index)... | codefeedback |
Write a C# method that takes an array of integers and shuffles it without using any built-in shuffling functions or algorithms. The method should ensure that each element in the array is moved to a different index than its original position. The shuffled array should still contain all the elements from the original arr... | codefeedback |
Create a feature for predicting a customer's subscription plan based off their purchase history.
The customer has purchased 10 shirts, 5 hats, and 15 pairs of jeans in the past 6 months. | codefeedback |
Implement an algorithm to reverse a string in Java without using any built-in string manipulation methods or additional data structures. The algorithm should have a time complexity of O(n) and a space complexity of O(1). | codefeedback |
Create a SQL query to find the total sales for product category ‘clothing’ where the sales date is between January 1, 2020, and December 31, 20 | codefeedback |
Create a SQL query to find the total revenue for services in the month of February, excluding any services with a negative revenue. The query should also calculate the average revenue per day for the month of February. Additionally, provide the name and contact details of the customers who have generated the highest re... | codefeedback |
Rewrite the following SQL query so that it produces the same result but in an efficient way, without using any subqueries.
SELECT Orders.*
FROM Orders
INNER JOIN OrderItems ON Orders.OrderId = OrderItems.OrderId
INNER JOIN Products ON OrderItems.ProductId = Products.ProductId
WHERE Products.CategoryId = 2 | codefeedback |
Create an array of ten unique prime numbers within the range 100 to 200. | codefeedback |
Create a C++ algorithm to compute the Fibonacci sequence, but you are not allowed to use recursion. | codefeedback |
Suggest an algorithm for sorting a list of integers in descending order. The algorithm should have a time complexity of O(n^2) and should not use any built-in sorting functions or libraries. | codefeedback |
Create a Java class to represent a TV show. The TV show should have the following attributes:
- Title: A string representing the title of the TV show
- Genre: A string representing the genre of the TV show
- Duration: An integer representing the duration of the TV show in minutes
- EpisodeCount: An integer representing... | codefeedback |
Design an algorithm to find the shortest path in a maze using JavaScript, but you are not allowed to use any graph traversal algorithms such as Breadth First Search or Dijkstra's algorithm. | codefeedback |
Count the number of vowels in a sentence, but only consider vowels that occur after a consonant and before another consonant. Ignore any vowels that occur at the beginning or end of a word.
Example input: "The quick brown fox jumps over the lazy dog"
Expected output: 2
Example input: "She sells seashells by the seash... | codefeedback |
Develop a code in Java to calculate the Body Mass Index (BMI) given the height and weight of a person, and classify the person into different BMI categories (underweight, normal weight, overweight, and obese) based on the calculated BMI.
Requirements:
1. The code should take user input for height in meters and weight ... | codefeedback |
Create a JSON object from the following data provided, where each data entry is represented as a separate object within an array:
1. Name: John Smith, Age: 34, Country: US
2. Name: Jane Doe, Age: 28, Country: Canada
3. Name: Alex Johnson, Age: 42, Country: UK
Ensure that the JSON object is created using the most effic... | codefeedback |
Given two lists, create a new list containing the elements of both lists, but with the following conditions:
1. All elements from list1 should come before any element from list2.
2. The elements in the new list should be in ascending order.
list1 = [1, 3, 5, 7]
list2 = [2, 4, 6]
Expected output: [1, 2, 3, 4, 5, 6, 7... | codefeedback |
Write pseudocode to find the average of an array of numbers, excluding any negative numbers. | codefeedback |
Given a list of numbers, print the numbers and their corresponding squares in ascending order.
list = [4, 5, 7, 8]
Time Complexity Requirement: O(n log n)
Space Complexity Requirement: O(n)
Note: The original question only required printing the numbers and their squares. The rewritten question requires sorting the ... | codefeedback |
Write a function to check if a given binary tree is a valid binary search tree, where the time complexity should be O(n) and the space complexity should be O(1). | codefeedback |
Please generate a system variable in C language that stores the current date and time in a specific format: "YYYY-MM-DD HH:MM:SS". The system variable should update every second and display the updated date and time in the specified format. Additionally, you should ensure that the program terminates gracefully when the... | codefeedback |
Change the data type of the following list to a dictionary. Each dictionary entry should have a key-value pair where the key is the name of the person and the value is a dictionary containing their age and hobbies. The list contains multiple entries in the following format: [name, age, hobby].
list = ['John', '26', 'M... | codefeedback |
Return a subset of a given array where the sum of all elements in the subset is the maximum possible value, given that the subset size is exactly K.
arr = [3, 6, 2, 5, 7, 4], K = 3 | codefeedback |
How would you write a program to find the number of prime numbers between 0 and 1,000,000? | codefeedback |
Create a REST API in python that takes a string as input and returns the reversed string. Additionally, implement a feature that removes all the vowels from the reversed string before returning it. | codefeedback |
Build a Python program to transform a string in a dictionary.
String: " John, 26, Movie Watch, Jane, 31, Book Reader, Charlotte, 25, Music Listener"
Requirements:
1. The input string will always be in the format "Name, Age, Hobby, Name, Age, Hobby, Name, Age, Hobby, ...".
2. The names can contain any alphanumeric char... | codefeedback |
Write a SQL command to count the number of rows from a table ‘Orders’ that meet the following conditions:
- The order was placed in the last 30 days.
- The order total is greater than $100.
- The customer is located in a specific city (e.g., New York).
- The order was not cancelled. | codefeedback |
Build a model using scikit-learn that classifies the given text data into three categories: 'Positive', 'Neutral', or 'Negative'.
The customer service was great, and I will definitely recommend this product to others. | codefeedback |
Create a tree data structure for the following information, where each node contains a character from the given string:
a) "Naruto"
b) "Sasuke"
c) "Boruto"
d) "Sarada"
Additionally, each node should also store the number of occurrences of the character within the given string. | codefeedback |
Write a function that takes a string as an argument, reverses the words in the string, and returns the reversed string. Each word in the string should maintain its original order, but the order of the words in the string should be reversed. | codefeedback |
Create a JavaScript function that converts all the characters in a string to uppercase, while also reversing the order of the characters in the string. | codefeedback |
Create a C++ function that finds the frequency of each character in a string and stores the frequency in a hashtable. The function should have a time complexity of O(n), where n is the length of the string. The hashtable should be implemented using separate chaining for collision resolution. | codefeedback |
Identify and fix the bug in the given code snippet.
```
function double_sum(nums) {
let sum = 0;
for (let i = 0; i < nums.length; i++) {
sum += nums[i] * 2;
}
return sum;
}
```
Write a detailed explanation of the bug and how you fixed it. | codefeedback |
Construct a program to parse a JSON array with the additional requirement that the program should calculate the average age of the individuals in the array. The program should also display the name of the oldest person in the array. Additionally, the program should validate that each object in the array has a "name" an... | codefeedback |
Rewrite the given code to calculate the sum of all numbers from 1 to a given input number, `num`, using a recursive approach.
Your solution should have a time complexity of O(n), where n is the value of `num`. | codefeedback |
Generate a code snippet to find the highest common factor of two given numbers using only bitwise operators and without using any arithmetic operators. | codefeedback |
You should create a Java program to implement a binary search with a twist. Instead of searching for a specific value in a sorted array, your program should search for a range of values within the array.
The program should take an input array of integers and two target values: lower and upper. It should then return th... | codefeedback |
Generate a code snippet to convert a given string to uppercase without using any built-in string manipulation functions or methods. | codefeedback |
Write a JUnit test case to test if the sum of two numbers is correct. The test case should also validate that the sum is greater than 100. | codefeedback |
Print out the nth number of the Fibonacci sequence, where n is a user-inputted positive integer. | codefeedback |
Explain the concept of recursion in Java and provide an example of a recursive function that calculates the factorial of a given number. | codefeedback |
What is the purpose of a try-catch block in Python when handling exceptions raised by asynchronous functions that use coroutines and generators? | codefeedback |
You are given an array of strings. Your task is to output the top 3 strings that have the greatest length. If there are multiple strings with the same length, output them in the order they appear in the array.
Example:
Input: ["Pineapple", "Apple","Banana", "Strawberry", "Grape"]
Output: ["Pineapple", "Strawberry", "B... | codefeedback |
Write a Python function to compute the factorial of an integer, with the additional requirement that the function should handle negative integers and return None for negative inputs. | codefeedback |
Generate a random 2-digit number that is divisible by 7 using JavaScript. | codefeedback |
Compute the maximum product of three integers in an array. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.