instruction_seed stringlengths 0 26.4k | source stringclasses 4
values |
|---|---|
Write a code to extract the length of the longest sentence in a given text. The text should be at least 100 words long and contain sentences of varying lengths. Additionally, your code should exclude any sentences that contain numbers or special characters. | codefeedback |
Create a JavaScript object to fulfill the following purpose
Create a calculator that can add, subtract, multiply and divide two numbers. Additionally, the calculator should have a functionality to calculate the factorial of a given number. The calculator should also be able to calculate the square root and raise a numb... | codefeedback |
Create a function that returns the sum of the Fibonacci sequence to the nth number, while ensuring that the function has a time complexity of O(n) and does not use recursion. | codefeedback |
Write a code to identify the longest palindrome in a given string. A palindrome is a word, phrase, number, or other sequence of characters that reads the same forward and backward. For example, "kayak" and "racecar" are palindromes.
You need to handle both odd and even-length palindromes. For example, in the string "l... | codefeedback |
Use recursion to construct a list of the first 20 powers of two (1, 2, 4, 8, ...). | codefeedback |
Create an HTML web page that contains two text fields and two buttons.
1. The first text field should only accept numerical input.
2. The second text field should only accept alphabetical input.
3. The first button should be disabled until both text fields are filled.
4. Upon clicking the second button, the values en... | codefeedback |
Sort the given array of strings by their length in descending order. If two strings have the same length, sort them lexicographically in ascending order.
Array: ['hello', 'hi', 'howdy'] | codefeedback |
Invert the given dictionary, but exclude any keys that contain the letter 'a'.
Dictionary: {'ab': 1, 'bc': 2, 'cd': 3, 'de': 4} | codefeedback |
Create a function that takes two arguments, a list of strings and a string and returns the number of times the passed in string appears in the list. If the list is empty or the passed in string is empty, return -1.
words = ['hello', 'hi', 'world', 'foo', 'bar', 'hello']
given_string = 'hello'
# Erroneous Code Referen... | codefeedback |
Construct a class that takes a string and capitalizes the first letter. Additionally, implement a method that reverses the capitalization of all other letters in the string. | codefeedback |
Write a code that takes in two strings and determines whether they are anagrams of each other. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The code should have a time complexity of O(n), where n is the length of the input strings. The code should not use any built-in func... | codefeedback |
Write a JavaScript program to generate a random hexadecimal color code that starts with the letter "A". | codefeedback |
Write a JavaScript program to create an array with the first element as the maximum and all other elements as the minimum value of the previous element, but the minimum value should be rounded down to the nearest integer. The resulting array should also exclude any negative values.
let arr = [5, 4, 3, 2, 1]; | codefeedback |
Create a program which takes two strings as input and checks if they are anagrams of one another. An anagram is a word or phrase formed by rearranging the letters of another word or phrase. The program should not only check if the strings have the same set of characters, but also check if the frequency of each characte... | codefeedback |
Using Java, write a function to find the count of all prime numbers between a given range.
int start = 1;
int end = 1000; | codefeedback |
Create a Python function that takes a string and prints out its reverse, but without using any built-in functions or libraries that directly reverse strings. You may only use basic string manipulation methods.
# Example
**Input:**
string = "Hello world!"
**Output:**
"!dlrow olleH" | codefeedback |
Design a class named Circle that can store information about a circle and perform calculations on it. The class should have the following methods:
1. `get_radius`: Returns the radius of the circle.
2. `set_radius`: Takes a parameter `radius` and sets it as the radius of the circle.
3. `get_diameter`: Returns the diame... | codefeedback |
Implement a recursive function to calculate the factorial of a positive integer number, given by the user as an argument. The function should handle edge cases where the input is zero or a negative number, returning an appropriate error message. Additionally, the function should also handle large inputs efficiently, co... | codefeedback |
Write code to create a list of length 10 with random integers between -1000 and 1000. Additionally, ensure that the list does not contain any duplicate values. | codefeedback |
Generate a sequence of strings according to the following pattern:
1. The first string in the sequence should be "1".
2. For each subsequent string in the sequence, concatenate the previous string with its length.
3. Repeat step 2 until the desired number of strings in the sequence is reached.
For example, if the desi... | codefeedback |
Create a code to display all unique pairs from the following list in ascending order.
[1,2,3,4,5,6]
#Additional Requirements#
1. The code should not use any built-in functions or libraries that directly solve the problem (e.g., itertools.combinations).
2. The code should have a time complexity of O(n^2), where n is th... | codefeedback |
Create an iOS table view to display a list of items, where each item is a custom class that contains multiple properties (e.g. name, price, quantity). Implement a custom cell for the table view that displays all the properties of each item in a visually appealing manner. Additionally, implement swipe gestures on the ta... | codefeedback |
Given a list of strings, format the list in descending order of the number of characters in each string. Implement a function `format_list` that takes in a list of strings and returns the formatted list.
The function should have a time complexity of O(nlogn), where n is the number of strings in the list. You are not a... | codefeedback |
Write a function to multiply an array of n numbers by their sum, where n is the length of the array.
Example:
Input: [2, 3, 4, 5]
Output: 120
Note:
- You can assume that the input array will always have at least one element.
- The input array will only contain positive integers.
- The sum of the input array will neve... | codefeedback |
Write a program that counts the number of distinct prime numbers less than or equal to a given positive integer N. | codefeedback |
Design a class to represent a car with member variables for the make, model, year, and color. Additionally, implement a method to calculate the fuel efficiency of the car in miles per gallon (MPG) based on the distance traveled and the amount of fuel consumed. The fuel efficiency should be stored as a member variable a... | codefeedback |
Take two strings and concatenate them. Then, remove all the vowels from the concatenated string. Finally, reverse the resulting string.
Example:
Input:
String1: "Hello "
String2: "World"
Output:
"dlrWllH" | codefeedback |
Find and list all the prime numbers between 0-100, but without using any looping constructs like for, while, or do-while. | codefeedback |
Using Regular Expressions, search for all 3-digit occurrences in the given text. Each occurrence must be followed by the word "digit" and the word "occurrence" should be preceded by the word "total". The text should also include at least one 3-digit occurrence.
text = "The ship had a 590 foot cargo hold, filled with 2... | codefeedback |
Create a Python script that prompts the user to enter their name and then prints "Hello, [name]!" where [name] is the user's input. The script should continue to prompt for input until the user enters "exit". | codefeedback |
Generate a unique 10-digit number using the Python Random module. | codefeedback |
Given an array of integers, update the array by replacing all the zeroes with the nearest non-zero element on the left side of the zero. If there is no non-zero element on the left side, replace the zero with -1.
my_array = [1, 0, 2, 0, 3, 0] | codefeedback |
Analyze the output of the following shell command and identify the total number of lines containing the word "error", while also excluding any lines that start with a "#" symbol. | codefeedback |
Write code to remove the first item from a list of integers in Python, but ensure that the list contains at least 5 elements and the removed element is added to a separate list called "removed_numbers". The original list should be sorted in descending order after the removal.
numbers = [2, 3, 4, 5, 6, 7, 8]
removed_n... | codefeedback |
Explain the concept of overflow and underflow in the context of unsigned integers and signed integers in the C language. Provide examples to demonstrate each concept. | codefeedback |
How do you calculate the Levenshtein distance between two strings? Implement a function that takes in two strings as input and returns the minimum number of single-character edits (insertions, deletions, or substitutions) required to change one string into the other.
str1 = "abc"
str2 = "abd" | codefeedback |
Generate a valid HTML document with the following constraints:
- The document must include a header element containing a title element.
- The title element must have a minimum of 5 characters and a maximum of 10 characters.
- The document must include a body element containing at least 3 paragraphs.
- Each paragraph mu... | codefeedback |
Program a function to get the next element of a list, but with the following constraints:
- The function should have a time complexity of O(1).
- The function should not modify the original list.
- The function should be able to handle lists of any data type, not just integers.
- If the list is empty or contains only o... | codefeedback |
Write a program that scans a network and retrieves a list of all devices connected to it. The program should be able to run on Windows and should be implemented using a programming language of your choice.
The program should have the following requirements:
1. The program should be able to scan both IPv4 and IPv6 netw... | codefeedback |
Create a function that returns the subset of an array which has the lengths of its elements smaller than the given threshold, while also ensuring that the subset is in ascending order. The function should handle duplicate values in the array and should return the subset without any duplicates. The threshold value shoul... | codefeedback |
Find the output of the following code when the input is a large number, n.
def get_result(n):
fib = [0, 1]
for i in range(2, n):
fib.append(fib[i-2] + fib[i-1])
return fib
Note: Please provide the output as the sum of all the Fibonacci numbers up to the nth number, modulo 10^9 + 7.
For example... | codefeedback |
Create a function in Python to generate n! permutations of a given array.
arr = [1, 2, 3]
n = 6
Note: n! represents the factorial of n, which means the number of permutations will be the product of all positive integers less than or equal to n. | codefeedback |
Write a JavaScript program to rotate an array by a given number, but the rotation must be done in place without creating a new array. The original array should be modified directly. | codefeedback |
Create an algorithm to find out the longest common sub-sequence between two string inputs, where the sub-sequence must consist of alternating characters from the two strings.
Example:
Input:
String1 = "AGGTAB"
String2 = "GXTXAYB"
Output:
"LCS: GGTAB" | codefeedback |
Create a test harness in C++ to verify the correctness of the following function with the additional requirement that the function should have a time complexity of O(1).
// A function to calculate the nth Fibonacci number
// Input: nth Fibonacci number
// Output: nth Fibonacci number
int calcFib(int n)
{
if (n<=... | codefeedback |
Create a Java method that takes a string and returns the same string with all vowels replaced by asterisks (ie. "Hello" should return "H*ll*").
The input string can contain both lowercase and uppercase letters. The method should consider both cases when replacing vowels with asterisks.
String s = "Hello";
#Expected ... | codefeedback |
Generate a Python code that flattens a two-dimensional array and returns the sum of all its elements.
Input: A two-dimensional array of integers.
Output: The sum of all the elements in the flattened array.
Example:
Input: [[1, 2], [3, 4]]
Output: 10
Note:
- The input array may contain positive and negative integers... | codefeedback |
Optimize the runtime of this SQL query.
SELECT * FROM customers WHERE age > 30 AND city == "New York" AND gender == "Male" ORDER BY last_name DESC
Note: The database has millions of records and the query needs to return the top 10 results. | codefeedback |
Using the input, write a function that prints out the Nth Fibonacci number. Additionally, your code should be optimized to have a time complexity of O(logN). | codefeedback |
Write a function in Java that takes an integer and returns an array of all the prime numbers from 2 up to the number. The function should use a segmented sieve algorithm to efficiently find the prime numbers within the given range.
Constraints:
- The function should have a time complexity of O(n log log n), where n is... | codefeedback |
Create a function that performs a bubble sort of an array in JavaScript.
The bubble sort algorithm works by repeatedly swapping adjacent elements if they are in the wrong order. The algorithm continues until the array is fully sorted.
For example, given the array: [4, 7, 1, 3, 6, 9, 8, 10, 2, 5], the function should ... | codefeedback |
Find the lowest common ancestor in a binary search tree in C++.
| codefeedback |
Create a Python script to output the sum of the elements in a given 2-D array, but with the following modifications:
1. The array should be a randomly generated 2-D array with dimensions m x n, where m and n are positive integers.
2. The elements in the array should be randomly generated integers within a specified ra... | codefeedback |
Write a function that takes in a string and a character and returns the first index at which the character appears. The string will not contain any leading or trailing whitespace. The character will always be a lowercase alphabet. The string can have a maximum length of 1000 characters. | codefeedback |
Formulate a suitable machine learning model to perform topic clustering on a dataset of 1 million articles, while considering the time complexity to be below O(n^2) and achieving an accuracy of at least 90%. | codefeedback |
Write an SQL query to find the average salary of all the employees who have a salary greater than the average salary of employees with 10 years of experience. | codefeedback |
Write a function to create a retail price tag given a cost, taxes, discounts, and additional fees.
The function should handle multiple taxes and discounts.
cost = 5
taxes = [{"name": "sales_tax", "rate": 0.08}, {"name": "vat", "rate": 0.05}]
discounts = [{"name": "early_bird", "percentage": 0.2}, {"name": "loyalty", "p... | codefeedback |
Given an unsorted array of numbers, implement a Merge Sort algorithm to sort the array in ascending order.
Additional Instructions:
1. Do not use any built-in sorting functions or libraries.
2. Your implementation should be recursive.
3. You are not allowed to use extra space for merging the arrays. | codefeedback |
Convert the given JavaScript function to TypeScript and implement it as a class method with the following additional requirements:
1. The class must be named "OccurrenceCounter".
2. The class must have a constructor that takes an array of numbers as a parameter and assigns it to an instance variable named "numList".
3.... | codefeedback |
Write an HTML code snippet for creating a search box that includes the following features:
1. Add a placeholder text inside the search box that says "Enter your search query".
2. Add a submit button next to the search box labeled "Search".
3. Validate the search box input so that it cannot be submitted if it is empty.... | codefeedback |
Write the code for the following sorting algorithm.
Comb Sort | codefeedback |
Write an HTML program to display an output as a table. The program should also include a feature that allows the user to dynamically sort the table based on a specific column. | codefeedback |
What are the components of a class in Java? Provide a detailed explanation of each component and its purpose. Additionally, demonstrate your understanding by writing a sample class that includes all the components mentioned. | codefeedback |
Write a Java program for computing the product of two matrixes, where each matrix is represented as a two-dimensional array.
The program should take input for the dimensions of the two matrixes and check if matrix multiplication is possible. If the multiplication is possible, the program should then take input for the... | codefeedback |
Write a JavaScript program to accept a string and display the characters in reverse order. Additionally, the program should ignore any consecutive duplicate characters in the reversed string. | codefeedback |
Using Java, write the code to calculate the sum of elements in a two-dimensional array, but only consider the elements that are prime numbers.
int[][] arr = {
{2, 3, 8},
{4, 5, 1},
{7, 0, 6}
}; | codefeedback |
Suggest an efficient algorithm to search for a target element in a sorted array using Java. The time complexity of your algorithm should be better than O(n), where n is the size of the array. | codefeedback |
Output the sum of all the elements in the two-dimensional array, but only consider the elements whose values are prime numbers.
arr = [[2, 4, 6], [8, 10, 12], [14, 16, 18]] | codefeedback |
Change the code so that it swaps the contents of two variables without using a temporary variable or any built-in swapping functions.
a = 5
b = 10 | codefeedback |
Name 3 popular JavaScript frameworks, and explain the key features and advantages of each framework. | codefeedback |
Create a function that takes two strings as inputs and outputs their concatenation, but with the condition that the resulting string should only contain unique characters. | codefeedback |
prompt the user to enter a positive integer, then output it in a sentence while also stating whether it is a prime number or not. | codefeedback |
Using the given input, modify the code to remove all occurrences of "abcd" and "efgh".
string s = "abcd abcd abcd abcd efgh efgh efgh efgh"; | codefeedback |
What is the name of the following component of a computer system:
A component that can perform complex data processing and calculations, involving multiple logical steps and decision-making. | codefeedback |
Generate a valid MySQL query to retrieve a column from a table where the column is a concatenation of two other columns from the same table, with a condition that only rows where the concatenated column starts with a specific letter are returned. | codefeedback |
Write a python code to calculate the area of a triangle given the coordinates of its three vertices: A(x1, y1), B(x2, y2), and C(x3, y3). | codefeedback |
Create a function in Python that adds two numbers, but the numbers must be positive integers less than 1000. | codefeedback |
Implement Binary Search in Python
You are given a sorted list of integers. Implement a function `binary_search` that takes in the list and a target integer and returns the index of the target integer if it is present in the list, or -1 if it is not.
The function should have a time complexity of O(log n), where n is t... | codefeedback |
Calculate how many distinct values can be inserted in a binary tree containing N nodes, where N is a positive integer. | codefeedback |
Generate an XOR function in C++ that takes in two integer arguments and returns the XOR result. Additionally, the function should handle cases where one or both of the input arguments are not valid integers and throw an exception. | codefeedback |
Generate a function in Java for finding the largest prime number in an array of positive integers. | codefeedback |
Write a Java program to sort the elements of an int array in the descending order without using any built-in sorting functions or external libraries. The time complexity should be O(n^2) or lower. The array may contain duplicate elements and its length can be up to 10^6. | codefeedback |
Write a Swift code to print out the signature of a function that takes two parameters, both of type Int, and returns an Int. The function should also have a requirement that the sum of the two parameters must be greater than or equal to 10. | codefeedback |
Create a new table in a database named 'customers' with the specified columns. In addition to creating the table, also define the data types and constraints for each column. Ensure that the column names are unique and that appropriate primary and foreign keys are set up. Additionally, add a timestamp column to track th... | codefeedback |
Write an SQL query to select the students who scored higher than the average in Maths, and have a minimum of 3 years of experience in programming. | codefeedback |
Output the nth Fibonacci number in JavaScript, where n can be as large as 10^6. | codefeedback |
Create a function in JavaScript to implement Newton's Method of Numerical Approximation, but ensure that the function can only use a maximum of 5 iterations to approximate the solution. | codefeedback |
Create a calculator in Python that can handle complex mathematical expressions, including parentheses and exponentiation.
(2 * 3)^2 + 5 - 4 * (6 / 2) | codefeedback |
You are presented with a string which contains a code snippet. Extract the variable types from this string. The code snippet may also contain nested objects and arrays. | codefeedback |
Create a web server in Java to handle multiple concurrent POST requests with heavy processing and large data payloads. | codefeedback |
Write an SQL query to find all the customers who've purchased at least two items in the last month and have a total purchase amount greater than $100. | codefeedback |
Create a class in jQuery to handle user authentication. The class should have the following functionality:
1. Accept a username and password as input from the user.
2. Validate the username and password by checking if they meet certain criteria. The criteria should include at least 8 characters for the password, and a... | codefeedback |
Write a JavaScript function to search a string for a specified value and return the position of the match. The function should also handle cases where the search value is a regular expression.
searchString = "banana"
searchValue = "a" or /a/ | codefeedback |
Create an algorithm in JavaScript to find the closest pair of points from a given set of points. The distance between two points should be calculated using the Euclidean distance formula.
let points = [[2, 0], [4, 4], [-2, 2], [-3, -4], [4, -2]];
To solve this problem, we can follow these steps:
1. Create a helper f... | codefeedback |
Generate a regular expression to match a string of consecutive numbers with a minimum of 4 digits. The string should not contain any whitespace characters and should be enclosed within double quotes. Additionally, include an erroneous code snippet that attempts to achieve the same result using a different approach, but... | codefeedback |
Can you code a solution to Bubble Sort an array of integers in descending order?
[5, 4, 3, 2, 1] | codefeedback |
Write a bash script that searches for a given text string in a directory tree recursively, excluding files with specific extensions and displaying the number of occurrences of the text string in each file. | codefeedback |
Create a React component that renders a table containing the records from an array of objects. The table should have the following additional features: sorting by name in ascending order, filtering by age greater than or equal to 25, and pagination with 2 records per page. The table should also display the total number... | codefeedback |
Implement a function to return the element that appears most frequently in a list, considering only elements that appear at least twice. The input list will contain at most 10^6 elements, and each element will be an integer between 0 and 10^9. | codefeedback |
Create a Drupal 8 theme that implements a 3 column layout with a header, side bar, content and footer. Additionally, the header should have a fixed position at the top of the page, the sidebar should have a fixed width, and the content should be responsive and adjust its width based on the screen size. Furthermore, the... | codefeedback |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.