instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a Python code to check if the given string contains only prime numbers. | 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.
list = [... | codefeedback |
Create two variables x and y with values 0 and 1 respectively and assign x to y using only the bitwise operators. | codefeedback |
Write a JavaScript code to filter an array of strings that begin with the letter `A`, have a length of 5, and contain at least one vowel.
let arr = ["Apple", "Banana", "Ant", "Cat", "Arson"]; | 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 |
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.
$data = array("John"=>45, "Bob"=>67, "Ann"=>55, "Mike"=>67, "Alice"=>45, "Tom"=>80); | codefeedback |
Implement a function that can convert a number from a given number system to another.
Input: The number 60 in binary to be converted to hexadecimal. | codefeedback |
Generate a SQL query to retrieve a list of all the movies released in 2019, along with their respective genres. | 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. | 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. | codefeedback |
1. Create a function called "initialize_list" that takes in a parameter called "start" and returns a list containing numbers from "start" to "start+99".
2. Inside the "initialize_list" function, use a loop to iterate from "start" to "start+99" and append each number to a list.
3. Return the list of numbers.
4. Call the... | codefeedback |
Design a binary search tree that has the following values in the given order and also satisfies the following constraints - 5, 4, 11, 6, 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 node should... | codefeedback |
Design an algorithm to summarize a long text while ensuring that the summary is grammatically correct and maintains the original context and meaning. | codefeedback |
Given a string, create a method to remove all empty spaces and punctuation from the string. The string may contain any printable ASCII characters including alphanumeric characters, special characters, and punctuation. The method should also handle multiple occurrences of empty spaces and punctuation within the string.
... | codefeedback |
Edit the following JavaScript code so that it rounds a number to the nearest integer.
However, this time, you need to implement the rounding functionality without using any built-in rounding functions or Math library.
function roundNumber(x) {
return x;
} | codefeedback |
Create a method to find the shortest word in a given array of strings. The method should ignore any words that contain digits or special characters. | codefeedback |
What is the minimum number of arguments needed to call the function "foo" where one of the arguments must be a dictionary and another argument must be a list of integers? | codefeedback |
Write a Java program that calculates the sum of all numbers from 1 to 1000 and prints the result. | codefeedback |
Write a function that takes in a string as input and outputs each character of the string three times, with a space in between each repetition. For example, if the input string is "hello", the output should be "h h h e e e l l l l o o o". The function should have a time complexity of O(n), where n is the length of the ... | 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. | 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.
employee_id: 101, employee_name: John | codefeedback |
Write an SQL query to retrieve all students from the table "Students" who have scored more than 90 marks and order them by their "grade" in descending order. | 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 number as an argument and returns the sum of the cubes of its digits. | codefeedback |
How do you handle errors and exceptions in JavaScript? | codefeedback |
Construct an SQL query to find all records where the column ‘department’ equals ‘sales’ and the column ‘salary’ is greater than 5000. | 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 |
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^6 characters. The function should also take into account the frequency of each letter in th... | codefeedback |
Generate a random boolean value using JavaScript, but ensure that the probability of getting true is exactly 1/3 and the probability of getting false is exactly 2/3. | codefeedback |
Create a function in Java to take a sentence as input and return a list of all the unique words in the sentence, excluding any common stop words such as "a", "the", and "and". The function should also ignore any punctuation marks and consider the sentence to be case insensitive. | 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. | codefeedback |
Create a program to encrypt a given text using the Caesar cipher encryption 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 las... | codefeedback |
Create an interactive web application for a number guessing game using HTML, CSS, and JavaScript. The game should allow the player to choose a difficulty level (easy, medium, hard) and set a maximum number of attempts. The player should be presented with a random number within a specified range based on the difficulty ... | codefeedback |
Suggest a 3D modelling software specifically for creating architectural designs with intricate details and realistic textures. | codefeedback |
Design a function in JavaScript to print all prime numbers between 1 to n, where n is a positive integer. | codefeedback |
How would you modify the query to print the average grade of the students, only considering grades above 90?
SELECT name, grade FROM Students WHERE grade > 90; | codefeedback |
Write a query in PostgreSQL to find the total number of students who have scored above 90% and have not missed any classes. Additionally, exclude any students who have been enrolled for less than 6 months. | codefeedback |
Determine the frequency of each unique word in a sentence using a hashmap in JavaScript. The solution should ignore case sensitivity and remove any leading or trailing punctuation from each word. The sentence can contain alphanumeric characters, spaces, and punctuation marks. The output should be sorted in descending o... | codefeedback |
Create a C# method to calculate the Nth Fibonacci number, where N is a non-negative integer less than or equal to 30. | codefeedback |
Create a Node.js server to handle POST requests and store the incoming data in a MySQL database. | codefeedback |
Generate a valid HTML page given the body contents, but the body contents should be 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 generated HTML page should include the necessary doctype declaration and any other requ... | codefeedback |
Create a C++ class to store data of an employee
Employee Data: employee_id, name, salary
Add the following additional features to the class:
1. Implement a method to calculate the monthly salary after deducting taxes. Assume a fixed tax rate of 20%.
2. Implement a method to compare two employees based on their salar... | codefeedback |
Rewritten Test:
Write a Python class to represent a binary search tree. The class should have the following methods:
1. `insert(value)`: Inserts a new node with the given value into the binary search tree.
2. `delete(value)`: Deletes the node with the given value from the binary search tree.
3. `search(value)`: Searc... | 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 and false otherwise. | codefeedback |
Create a 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. | codefeedback |
Create a function that takes in a string of characters and returns a new string containing only the characters that are in the odd 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 |
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.
Table structure:
Purchase (Customer_ID, Purchase_Date, Purchase_Length) | codefeedback |
Create a REST API endpoint to retrieve specific user data from the database. The user data should include the user's 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, and address.
When retrieving the user data, en... | 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, and the interactions they have had with the company's website and mobile app. | 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 |
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. Finally, t... | codefeedback |
Write a two-column HTML table with the film names as the first column and the release year as the second column. Include the film director's name as the third column. The table should also have alternating row colors for better readability.
Harry Potter (2001, directed by Chris Columbus)
Avengers (2012, directed by Jo... | codefeedback |
Construct a machine learning model to classify a given dataset into two class labels. The dataset consists of 100,000 records with 50 features each. The features are a mix of numerical and categorical data. The class labels are imbalanced, with one class having only 5% of the records. The model should achieve an accura... | 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.
[332, 555, 898, 876] | codefeedback |
Manipulate the string "Hello, World!" using the correct Python function that will replace the word "Hello" with "Goodbye", but ensure that the replacement is case-sensitive and only replaces the word "Hello" if it appears at the beginning of a sentence (i.e., capitalized and followed by a comma). | 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 |
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. | codefeedback |
Create a HQL query to sort records by descending order based on two columns - "age" in descending order and "name" in ascending order. | codefeedback |
Write a SQL query to select only unique rows from a table that contains duplicate records. | codefeedback |
Create a HTML web page with a header, a body and a footer section. The header section should contain a navigation bar with at least three menu items. The body section should have a main content area with at least three paragraphs of text. The footer section should include social media icons that link to corresponding s... | codefeedback |
Write a function that returns the day of the week given a date in the format 'YYYY-MM-DD'. The function should support dates from 1900 to 2099.
For example:
date = '2020-12-30'
Expected output: 'Wednesday'
#Additional Challenge#
Improve the efficiency of your function to have a time complexity of O(1). | codefeedback |
Write an R statement to calculate the probability of getting a prime number from a range of 1 to 100. | 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 transposition cipher. | 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 10 strings and each string can have a max... | codefeedback |
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 element shou... | 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 |
Convert the hexadecimal number FA to its binary form, using bitwise operations only. | codefeedback |
Output a Regex 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), a... | 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 also include validation to ensure that the email address entered is in a valid format. Additionally, implement a feature that allows the user to preview the selected... | codefeedback |
Calculate the area of a triangle with base b=4 and height h = 5 using a recursive approach. | codefeedback |
Generate an array with the following pattern [3, 6, 12, 24, ....2048] | 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). | 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
To solve this problem, we can follow these steps... | codefeedback |
Optimize the following C code with a faster algorithm.
// C Program to find the second minimum element in an array
#include <stdio.h>
int main()
{
int array[100], minimum, second_minimum, size, c, location = 1;
printf("Enter the number of elements in array\n");
scanf("%d",&size);
printf("Enter %d intege... | 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).
Input: A large dataset of text consisting of sentences.
Output: A classification for each sentence, either "opinionated" or "objective".
Example:
Input:
- "I think this r... | 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. | codefeedback |
Given a nested XML structure, parse and extract the value of a specific element.
XML Structure:
<library>
<section id="1">
<category>Programming</category>
<books>
<book id="1">
<title>Python for Dummies</title>
<author>John Smith</author>
</b... | codefeedback |
Write a script for swapping two variables in Ruby, but you are not allowed to use any temporary variables or the built-in Ruby method for swapping values. | 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 |
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 2.
- The third variable should be assigned with the ... | 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 |
Describe the main differences between Cython and Python in terms of syntax and functionality. Provide examples to support your explanation. | codefeedback |
Create a series of nested for loops in Java to print the numbers from 1 to 10 in descending order on separate lines. Additionally, modify the code to skip printing the number 5. | codefeedback |
What is the difference between deep learning and traditional AI? Provide an example of how deep learning can be applied in a real-world scenario and explain the steps involved in implementing it. | 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 2. Otherwise, print "Skipped: " followed by the number on a new line. | 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 a program in Java to reverse an array of integers without using any additional data structures or built-in functions. The program should modify the given array in-place.
Example:
Input: [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Additional Constraints:
- The algorithm should have a time complexity of O(N), where N... | codefeedback |
Use the reduce method in JavaScript to find the maximum value that is divisible by 3 in a given array of positive integers. The array will always contain at least one element that is divisible by 3.
Example Input: [9, 2, 5, 12, 21]
Example Output: 21 | 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.
"Hello, World! How are you? Are you enjoying your day?" | codefeedback |
Create an algorithm to traverse a binary tree in post-order in Python. | 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. | codefeedback |
Given two strings, sort them in order of the number of vowels present in each string, with the string having the most vowels appearing first. If both strings have the same number of vowels, then sort them in alphabetically ascending order.
"javascript"
"python" | codefeedback |
Write a Python program to determine if an input string is a valid IPv4 address. | codefeedback |
Write an SQL query that returns the average age for students in a specific class, where the class is identified by a unique class ID.
Additionally, retrieve the maximum age, minimum age, and count of students in the class.
Hint: You may need to use aggregate functions and group by clause in your query. | 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 checking if the strings are anagrams, you should also consider case sensitivity and ignore any spac... | codefeedback |
Write a regular expression to match the phrase "hello people" with the following additional conditions:
- The phrase should be case-insensitive (i.e. it should match "Hello people", "HELLO PEOPLE", etc.)
- The phrase should not be preceded or followed by any other word characters (i.e. it should not match "oh hello peo... | codefeedback |
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 matrix:
... | codefeedback |
Construct a query in SQL to group records by some value and display the count of each group. Additionally, sort the groups in descending order based on the count. | 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. | 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. | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.